LoRaWAN soil moisture solar device using Helium network

My child have a small garden where he has tomatoes, mint, different vegetables and fruits. We want to know when it is the right time to water it.

This was also an opportunity to use my Rak Wisblock kit fro something else than just writing some blog post. I’ve chosen to connect the device over Helium network because I’m making different tests on this network currently but it is also working on TheThingsNetwork the same way. So you can use the network most covering you around.

The data will be displayed on Cayenne Mydevice for getting a quick dashboard for displaying the information. In this blog post I’m going to describe the main steps and the needed hardware to make your own device.

Pr-requisites

We need some hardware and this is the reason why it has taken me some time to start this project: the delivery time from RAK to get all the missing components has a bit long. I assume it is due to the electronic components shortage we are currently facing.

Hardware components

The total cost for this device using wisblock product is about $79.9 plus import taxes. That’s a bit expensive for such gadget in my point of view but you can save $15.2 as the environmental sensor is a plus but not mandatory. You can also remove the solar panel and use a bigger battery as the system should not require a large power for a long life duration. So basically you ca make it for less than $50 with some optimizations.

Library prerequisites

You also need some libraries for the Arduino environment

  • Rak Wisblock environment
  • Cayenne LPP
  • ClosedCube_BME680

Soil moisture sensor

The principle is to use 2 big and long screws and to pass a current over it and measure the voltage over them. Voltage is really low when the garden is dry and growing when the garden is wet (basically soil resistance vary with water percentage). So the way to measure this is just to use the Wisblock ADC to measure the voltage on one of the screws when the other one delivers 3.3V.

Soil moisture sensor

As you can see on the picture, I used 2 long screws. That way it is easy to connect to the plastic enclosure without have water entering into it.

The most problematic things was to create a contact between a wire and the screws to connect them later to the Wisblock board. I’ve tried soldering but I’m not correctly equipped for such operation. So the easiest way has been to screw the screws with the wire to make a strong contact between them and the enclosure. It has been working well.

I also add some duct tape on the screws to measure the soil moisture not on surface but deeper.

The last problem you can see here is the ability to find a place to place the screws in the box: the position here could be perfect but the Wisblock enclosure is not delivered with screws to fix the Wisboard inside… and the screw size is something like M2.5 so something you never have in your stock even for a maker like me… So you need to use the two provided spacer, really high and this prevent to correctly push the screw inside the box. This is why there are two different size. It’s not a feature, just an bug.

I had another screw issue with Wisblock: sensor’s board did not came with little screws to fix them on the main board. Honestly I do not understand this bug as such tiny screws are mandatory, costs nothing and impossible to find out of RAK shop. So they should be delivered with every sensor board.

Assembly

Once I found solution about screws issues, the assembly of the components has been really fast. That the advantage of Wisblock: no soldering, just screwing and fast written code on Arduino platform.

Different Wisblock sensors assembled for the connected soil moisture device

On the picture above, you can see all the components of the system: You have the mother board, here screws with the spacer, with the RAK LPWAN core on the right, then the environmental sensor on the center top and the I/O board on the left side.

We have on the right the LiPo connector on the bottom and the solar panel connector on the top.

Solar Helium connected soil moisture sensor mounted

Once we have everything mounted in the enclosure, everything is perfectly entering in it. The long screws are connected to A0 pin for one of them and 3.3V for the other one. (I could have used an I/O powered only when the device it getting a measure, it would have been better).

The LiPo find a place on one of the side. The antenna also. As the Network is really good at home I did not make any effort in placing the antenna or using a better one.

Then the solar panel can be connected and the enclosure closed.

Source code & programming

The project source code is published on GitHub under Wisblock Soil moisture Solar name. You will find the Arduino files to copy locally to compile with Arduino environment and Wisblock environment. Then you need to make some setup.

CREATE a NEW HELIUM DEVICE

You need to create a new Helium device in the console.helium.com (I’m not going to go into details as you can refer to my Helium getting started blog post – at end of it). Once the device is added you can go to Devices tab and see the device details. You will see the credentials. By clicking on the double arrows you can display them like this to be more convenient to by copied /pasted into the source code. You can do the same for the App Key once you clicked on the eyes.

These credentials must be copied into the source code in the lora_handler.cpp flle:

device otaa setup

This allows to get your device connected to the network.

Add an integration with Cayenne MyDEVICE

As we want to see the sensor data in a dashboard and make no effort for it, the best way is to use Cayenne from mydevices. To link our device to this platform, we can use the existing connector in the helium console. So we need to create a new Label “Soil_moisture”, then we attach the device to this Label. After it, we create a new integration in Integration tab. Select myDevice as integration type.

Setup myDevice integration into Helium console

You just need to give it a name and attach it to the Label we have just created. That’s it. Nothing more to do on that part.

Configure MyDevice dashboard

Then you need to go to cayenne myDevices platform, register if you do not already have an account and add a new dashboard:

Create a new dashboard for Helium on MyDevices

You need to find Helium under LoRa for selecting the right source of data. The you need to search for Cayenne LPP type of device. This is a self describing protocol. So basically, within the data you have the information it is a temperature, humidity, pressure… And the different dashboard widget will be automatically created on data reception.

Select Cayenne LPP protocol

Once you have selected it, you need to enter some information to link the device with your dashboard:

Cayenne LPP device configuration for Helium

On this screen, you need to setup the DevEUI and to give it a name. For the name you put what ever you want but for the DevEUI, you need to enter the one given by the Helium console (see above)

Once done, the dashboard will be automatically created when it will have received the firsts frame (usually it needs 2 or 3 for displaying it).

Soil moisture solar device dashboard

Device setup

Before getting ready, we need to complete device setup. Before closing the device into the enclosure and put it in the garden, I recommend to make some tests. For this, in the main.h file you can enable logs and reduce the transmission time:

// Comment the next line if you want DEBUG output. But the power savings are not as good then!!!!!!!
//#define MAX_SAVE

/* Time the device is sleeping in milliseconds = 2 minutes * 60 seconds * 1000 milliseconds */
#define SLEEP_TIME 30*1000

Commenting MAX_SAVE and changing SLEEP_TIME will allow you to see the measure results on the serial console and have a transmission of new value on every 30 seconds. This will help you to ensure a correct configuration of your system. Once everything is ok you can be back on the initial values and program the device for the last time before getting installed in the vegetable garden.

Wisblock enclosure USB not correctly centered

The last issue I figured out was the USB connector hole in the enclosure. As it is not correctly centered once the RAK wisblock board is screwed inside it was not possible to use a standard USB cable. Fortunately I have some long head USB cables but you may not. So make sure your device is programmed or can be programmed before screwing everything or you could have some trouble to program it after.

It has taken me about 1:30 to make all of this working including code writing from the examples given by RAK. (the code quality I’m delivering is not at the quality level I like but it is good enough for this hack). This also includes all the related mechanical questions and the time searching some solution to replace the missing little screws. So that’s quite fast thanks to Wisblock solution.

Now it’s in the garden.

Share it !

The last possible step is to make this sensor public (basically to share it with my child). For this, in the cayenne dashboard, you need to click on (+) icon on the top to create a new specific dashboard. Then you can drag & drop sensors form different project to create a custom dashboard and you can make it public.

You can check my garden on the following page: https://cayenne.mydevices.com/shared/608d6e01518adb4d4a70c197/project/37797555-cd0a-42a0-9f2f-878c7cd09d53

Ping me on twitter if he missed to water it in time 😉

4 thoughts on “LoRaWAN soil moisture solar device using Helium network

    • One of the hotspot is about 30 meters away but the data are received by hotpots 2-3 km away too.
      I did not had a lot of investigation on this as the area is well covered. For sure the internal antenna has not been selected for world records 😉

  1. How did you attach your battery to the device? Did you use the specified connector? if so, where did you purchase?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.