Wireless Soil Moisture Monitoring With Raspberry Pi And Lorawan

Introduction

In this blog post, we will discuss a random yet interesting topic in the field of Internet of Things (IoT) - monitoring soil moisture levels using Raspberry Pi combined with LoRaWAN technology. This information can be beneficial for agriculture, landscaping, and environmental research, among others.

Our goal is to create a wireless sensor that measures soil moisture and sends the data to a central hub using a Raspberry Pi equipped with a LoRaWAN module. This central hub then uploads the data to the cloud for storage and analysis.

Hardware Components

You will need the following components to build the sensor:

  1. Raspberry Pi Zero W or any other Raspberry Pi version with Wi-Fi
  2. Capacitive Soil Moisture Sensor
  3. LoRaWAN module (e.g., Dragino LPS8 Gateway or The Things Indoor Gateway)
  4. Jumper wires
  5. USB Cable for Raspberry Pi

Setting Up the Raspberry Pi

First, set up the Raspberry Pi by installing the Raspberry Pi OS on an SD card and connecting it to your Raspberry Pi. Connect the LoRa module to the Raspberry Pi using jumper wires according to the module's pinout diagram.

Soil Moisture Sensor Connection

Connect the capacitive soil moisture sensor to the Raspberry Pi GPIO pins:

  • VCC to 3.3V
  • GND to GND
  • SIG (Signal) to GPIO4

Python Code for Soil Moisture Sensor

Now, let's go through the Python code to read the soil moisture level from the sensor connected to the Raspberry Pi. Create a file named soil_moisture.py and add the following code:

import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(4, GPIO.IN) while True: moisture_level = GPIO.input(4) print("Soil moisture level: ", moisture_level) time.sleep(1)

This script continuously reads and prints the soil moisture level as a digital value every second. You can adjust the reading frequency to suit your needs by changing the time.sleep(1) value.

Integrating LoRaWAN

To send the soil moisture data to a central hub, we need to integrate LoRaWAN using a module like 'LoRaWAN Gateway'. The general procedure includes:

  1. Connecting the LoRaWAN module to the Raspberry Pi.
  2. Setting up the LoRaWAN gateway.
  3. Configuring the Python script to send data via LoRaWAN.

For a specific integration guide, you can refer to the Dragino LPS8 Gateway documentation.

Conclusion

In this tutorial, we covered how to create a wireless soil moisture monitoring system using Raspberry Pi, a soil moisture sensor, and LoRaWAN technology. By sending soil moisture data to a remote server, it can be collected, analyzed, and monitored in real-time, enhancing decision-making in various fields, including agriculture, landscaping, and environmental studies.