Back to IoT Blog
Agriculture IoT 22 min read

Smart Agriculture: Soil Moisture Monitoring with LoRaWAN

Build a long-range, low-power soil moisture monitoring network for precision agriculture with automated irrigation control.

1. Project Overview

This project builds a complete smart agriculture system using LoRaWAN technology for long-range, low-power soil moisture monitoring across large fields. The system includes automated irrigation control based on soil conditions.

What You'll Build:
  • LoRaWAN soil moisture sensor nodes (battery-powered)
  • LoRaWAN gateway for long-range communication
  • Network server setup (ChirpStack or TTN)
  • Real-time monitoring dashboard
  • Automated irrigation control system
  • Solar power for remote sensors

2. Required Components

ESP32 LoRa ModuleESP32 with SX1276/SX1262 LoRa chip
Capacitive Soil SensorCorrosion-resistant moisture sensor
LoRaWAN GatewayRaspberry Pi + concentrator HAT
Solar Panel6V 2W for sensor power
Battery18650 Li-ion 2000mAh+
Waterproof EnclosureIP65 rated for outdoor use

3. Understanding LoRaWAN

LoRaWAN (Long Range Wide Area Network) is perfect for agriculture IoT:

4. Soil Sensor Setup

// ESP32 LoRaWAN Soil Moisture Node
#include <SPI.h>
#include <LoRaWan.h>
#include <Adafruit_SleepyDog.h>

#define SOIL_SENSOR_PIN 34
#define LORA_BAND 915E6  // Change for your region

// Calibration values
#define SOIL_DRY 3000
#define SOIL_WET 1500

void setup() {
  Serial.begin(115200);
  pinMode(SOIL_SENSOR_PIN, INPUT);
  
  // Initialize LoRa
  if (!LoRa.begin(LORA_BAND)) {
    Serial.println("LoRa init failed!");
    while (1);
  }
  
  // Join LoRaWAN network (OTAA)
  joinNetwork();
}

void loop() {
  // Read soil moisture
  int sensorValue = analogRead(SOIL_SENSOR_PIN);
  float moisture = map(sensorValue, SOIL_DRY, SOIL_WET, 0, 100);
  moisture = constrain(moisture, 0, 100);
  
  // Send via LoRaWAN
  sendMoistureData(moisture);
  
  // Deep sleep for 30 minutes
  enterDeepSleep(30 * 60 * 1000);
}

void sendMoistureData(float moisture) {
  LoRa.beginPacket();
  LoRa.print("MOIST:");
  LoRa.print(moisture);
  LoRa.endPacket();
  Serial.println("Data sent");
}

5. LoRaWAN Gateway Setup

Set up a Raspberry Pi-based gateway:

# Install ChirpStack Gateway Bridge
wget https://downloads.chirpstack.io/gateway-bridge/latest/chirpstack-gateway-bridge.deb
sudo dpkg -i chirpstack-gateway-bridge.deb

# Configure for your concentrator
sudo nano /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml

6. Network Server Configuration

Use The Things Network (TTN) or self-hosted ChirpStack:

7. Dashboard & Alerts

Integrate with Grafana or custom dashboard:

// Node-RED flow for TTN integration
[
  {
    "id": "ttn-input",
    "type": "ttn up",
    "name": "TTN Up",
    "app": "your-app-id"
  },
  {
    "id": "dashboard",
    "type": "ui_chart",
    "name": "Soil Moisture Chart"
  }
]

8. Automated Irrigation

Set up automatic watering based on thresholds:

// Irrigation automation logic
if (moisture < 30) {
  // Soil too dry - start irrigation
  digitalWrite(VALVE_PIN, HIGH);
  sendAlert("Irrigation started - Field Zone 1");
} else if (moisture > 70) {
  // Soil wet enough - stop irrigation
  digitalWrite(VALVE_PIN, LOW);
  sendAlert("Irrigation stopped - Field Zone 1");
}

9. Solar Power Setup

Power Budget Calculation:
  • ESP32 deep sleep: 10 ΞA × 23.5 hours = 0.235 mAh/day
  • Active transmission: 120 mA × 0.5 hours = 60 mAh/day
  • Total: ~60.24 mAh/day
  • 2000mAh battery = 33 days autonomy
  • 2W solar panel = full recharge in 1 day

10. Field Deployment

11. Troubleshooting

Poor LoRa Range

Sensor Reading Issues

Next Steps

Expand your smart agriculture system:

  • Add weather station integration
  • Implement multi-zone irrigation
  • Add soil temperature monitoring
  • Integrate with farm management software
  • Add pest/disease monitoring