LoraWAN Soil Moisture Sensor - Makerfabs

 Lorawan-Soil-Moisture-Sensor-1

As more and more customers are interested in LoRaWAN, I decide to make a LoRaWAN soil moisture sensor.

1. Project Description.

Makerfabs LoRa moisture sensor has been popular sold& used in open hardware community, but sometimes we get customers’ questions: How I can use your sensor with TTN/ Helium? Whenever we get these questions, we can only feedback: Er, there some difficulty…

The LoRa & LoRaWAN actually suits for absolutely different applications:
Physical-and-Communication-Layers-of-Lorawan
  • LoRa, mostly stands for local simple point-to-point communication, there sender and receiver are needed, it acts most like Physical layer in OSI, that the sender sends out the signal while the receiver gets it. LoRa suits for applications that need low-rate local point-to-point communication, ranging to a few kilometers.
  • LoRaWAN acts like the Network layer in OSI. It mostly is used in network that need to access to the internet. LoRaWAN acts like a local WIFI network, that deal with all the coordination/ addressing/ exception dealing, etc… Same as WIFI, a Router is needed in the network, that deal with these tasks and accession to internet. The difference is that, benefits from the longer range of LoRaWAN, there are some public LoRaWAN routers, that you may not need to install your router by yourself. Just think it you using the WIFI router in your neighborhood, or a phone registering on a station.

Makerfabs the LoRa moisture sensor is a LoRa module, the controller Atmega328P controls the LoRa module SX127X, with SPI, to broadcast the soil moisture and air temperature& humidity every 1 hour, any LoRa receiver in the range can get the info, and thus to decide whether or not to deal with it. It has no connection to the internet. Of course, some users program the controller Atmega328P to run the LoRaWAN protocol, with a LoRaWAN router, to connect to TTN or Helium and get succeed, such as these following projects:

● https://twitter.com/hexaspot/status/1593216730566123520
Lora-Soil-Moisture-Sensor-Project-1



● https://community.home-assistant.io/t/makerfabs-soil-moisture-sensor-v3-LoRaWAN-ttn-v3-and-ha-integration/446021
Lora-Soil-Moisture-Sensor-Project-2

But this needs the user to have high coding skilling, and there sometimes some exceptions as the Atmega328 limits resources.

With more customers interest in LoRaWAN, I decide to make a LoRaWAN soil moisture sensor.

2. Current LoraWAN Solutions.

There are mainly 2 structures for LoRaWAN projects:
● STM32 Controller+ SX126X

In this structure, the STM32 run the LoRaWAN protocol and also deal with filed application, such as the Seeed LoraE5.
Seeed-LoraE5

It is cheap and efficient. Users can run filed applications in the STM32(that also run LoRaWAN protocol), But the disadvantage is, users will need to remake all the codes, field applications codes such as sensor interaction, and the LoRaWAN protocol codes, whenever updates the filed application. Besides, it is hard to translate to other platforms, can be only stuck to the STM32 platform;

● Separate Controller+ LoRaWAN Modules

In this structure, a separate LoRaWAN module was used to run/deal with the LoRaWAN protocol, so the end-users do not need to consider any LoRaWAN-related coding, just control the LoRaWAN module by AT commands, the separated controller can be used to run customers’ filed applications only.
Solution
Advantages
Disadvantages
STM32 controller+ SX126X
Cost-effective
Filed application codes and LoRaWAN codes run simultaneously. Hard for coding& transplanting
Separate Controller+ LoRaWAN Module
1.Filed codes& LoRaWAN protocol codes be separated;
2. Easy to transplant in multiple controllers
Extra controller needed

Finally, I decided to use 2nd structure.
*The Seeed Lora E5 also has built-in firmware with AT commands, that can also be used as a LoRaWAN module in the 2nd structure.

3. LoraWAN Soil Moisture Sensor

As the LoRaWAN module, I select the AiThink RA08H, As the LoRaWAN modules connect to main controller via UART and AT commands, actually it’s easy to update to some other modules from other suppliers.

As for the main controller selecting, i considered the following candidates:
● Atmega328P: Popular used 8 bits controller, Arduino Uno compatible. But the most problem is its price… It is up to $5 in the IC shortage;

● SAMD21: The controller used in Arduino zero and our Maduino Zero Modules, built-in USB;
● RP2040: A relatively new controller by Raspberry Pi. Hot recently…

To make it hot, I selected the RP2040… er, which proves maybe not a good choice finally.

In 2 weeks, I made the hardware:
Lorawan-Soil-Moisture-Sensor-Diagram
  • The core controller is RP2040, of course, with extra 128M flash, it generates the PWM and thus to detect the soil moisture via capacitive method;
  • It also detects the air temperature& humidity via a sensor AHT10;
  • 3 AAA batteries are used to generate 4.5V voltage, to ensure the ADC is stable, although 2 AAA batteries, 3V, is actually OK, but as I tested in the LoRa Moisture Sensor, the ADC result drops as the main voltage drops, so making the VCC to 3.3V stable help making the ADC stable.

I have a LoRaWAN router in our office, the Dragino_LIG16, I created a simple LoRaWAN to internet accession quickly.  
Lorawan-Soil-Moisture-Sensor-Test

1. Local moisture& air data are uploaded to LoRaWAN TTN(the things network)
Sensor-Data-on-LoRaWAN-TTN

2. Also, the TTN supports transmitting the data to Thingspeak for visual checking:
Sensor-Data-on-Thingspeak
*For more info about TTN/ thingspeask setting, please refer to:

4. LoraWAN Soil Moisture Sensor Power Consumption

The total hardware/ software seems work great, but then I encountered a problem: Power Consumption.

A main advantage of LoRaWAN is its low power consumption, Makerfabs LoRa Moisture Sensor current is a few uA(7.1uA in sleeping mode), that is, with the 2*AAA batteries, it can work for at least a year(theoretically). But when I try to check the power consumption of the RP2040, I find it problem:


● In either Arduino& MicroPython, I do not get much support on the sleep mode setting, there little files, not mention to libs, about the RP2040 power saving. I found tomjorquera made the PICO low power setting, but it is driven by external interrupt, can not be reset from sleep by internal clock. Besides, it proves that the RP2040 current high even in dormant mode:
Power-Consumption

● Then, I have to transmit to Pico C/C++ SDK, the original RP2040 development tool released by Raspberry Pi team:

Pico-C-C++-SDK

But still, I found the sleep mode of RP2040 up to 1.03 mA, that is, theoretically, with 3 AAA batteries, the working time is less than a month, even with bare RP2040… This is not good for a LoRaWAN sensor.

By the way, as there not any libs for external modules, same as that in MicroPython& Arduino, for PWM generating/AHT10 interaction, I have to write them by ourselves in Pico C/C++ SDK, which takes a lot of time.

By 2022/11/18, I still do not get a better result. Personally, I think maybe the RP2040 not a good choice that need lower power, and lack of support on Arduino& MicorPython.

I am considering to switch back to Atmega328P, which I am much more familiar with and the current less than 1 uA (sleep mode), 0.1% of that for RP2040. The good news is that, its price is about $2 now, and maybe even lower in the near future, as there IC shortage ends up.

Keep tuned...

Check this video:

5. Update: New ATMega328P Lorawan Soil Moisture Sensor

As we decided to switch back to Atmega328P, the hardware design and production turns out quickly. Now, I am happy to announce that this new LoRaWAN soil moisture sensor is available.
ATMega328P-Lorawan-Soil-Moisture-Sensor

Makerfabs LoRaWAN soil moisture sensor uses the Atmega328P as the main controller, which is Arduino compatible, and AIthink RA08H as the LoRaWAN interface. As the sensor, this module uses capacitive method to test the soil moisture, and an AHT10 to test the air temperature& humidity.

ATMega328P-Lorawan-Soil-Moisture
Compares to the v1 version with RP2040, the core controller Atmega328P is the most modification.

With this controller, the module sleeping current is only 7.1uA and 4mA in LoRaWAN communication around. With our default setting, 1 hour per update, it can at least work for 1.5 years with 3 AAA batteries;
ATMega328P-Power-Consumption

To Help users create LoRaWAN applications quickly, Makerfabs provided the application firmware frame, which is based on Arduino IDE.

In the firmware frame, we have set the lower power module, PWM setting, etc, users can simply modify a few codes (Appkey/ AppEUI/ DevEUI), to achieve a LoRaWAN application in a few minutes. Also, you can modify the setting, such as LoRaWAN message interval, and add or remove functions freely in the codes.

With a LoRaWAN router, it is now easy to create a LoRaWAN application now.
Lorawan-Router


1. Configure the LoRaWAN router, in our demo application, we update the soil moisture data to LoRaWAN service TTN every 60 minutes, and display the output via Thingspeak;
2. Modify the end-device setting, including the LoRaWAN app/dev setting; by default, the result is updated every 1 hour.
3. Monitor the data via TTN or Thingspeak;
Data-Lorawan-Soil-Sensor
For all the above steps, Makerfabs has prepared a very detailed Wiki page for the learner, to create the first LoRaWAN application with TTN/Thinspeak, in a few minutes.

We believe the LoRaWAN could be a good solution for low-power, low-rate applications such as agriculture, and there will be more LoRaWAN sensors, including light sensor/ CO2 sensor, available at Makerfabs online store, If you have any ideas/suggestions about Makerfabs LoRaWAN products, feel free to contact us.

If you have any further questions about the LoraWAN soil moisture sensor, please just feel free to contact service@makerfabs.com.wink

Comments