SMART IRRIGATION SYSTEM
Automated soil moisture monitoring & intelligent pump control for water-efficient farming
OVERVIEW
What is the Smart Irrigation System?
The Smart Irrigation System is a fully automated watering solution built at Msoka IoT Lab. It monitors soil moisture levels in real time using capacitive sensors and automatically activates a water pump when moisture drops below a set threshold.
The system eliminates the need for manual watering schedules and prevents both over-watering and under-watering — two of the biggest causes of crop failure in small-scale Tanzanian farming.
The entire system runs on an ESP32 microcontroller and communicates with a web dashboard, allowing remote monitoring from a phone.
THE PROBLEM
What challenge does this solve?
Small-scale farming in Tanzania faces a critical water management challenge. Manual watering is time-consuming, inconsistent, and often leads to crop loss from either drought stress or root rot caused by overwatering.
Farmers working multiple plots simultaneously cannot monitor every bed continuously. The goal was to build a low-cost, reliable system that removes the guesswork from irrigation — letting the soil itself tell the system when water is needed.
PARTS LIST
Every component used to build the system.
| # | Component | Quantity | Purpose |
|---|---|---|---|
| 1 | ESP32 DevKit v1 | ×1 | Main controller + WiFi |
| 2 | Capacitive Soil Moisture Sensor | ×4 | Soil moisture reading (analog) |
| 3 | 5V Single-Channel Relay Module | ×1 | Pump switch control |
| 4 | Submersible Mini Water Pump (5V) | ×1 | Water delivery |
| 5 | Silicone Irrigation Tubing | ×1m | Water routing |
| 6 | 18650 LiPo Battery + TP4056 charger | ×1 | Portable power |
| 7 | Jumper wires + Breadboard | assorted | Prototyping connections |
| 8 | USB Power supply (5V 2A) | ×1 | Primary power source |
HOW IT WORKS
The four-step control loop, from sensor to action.
-
SENSE
Four capacitive soil moisture sensors are embedded in the soil at different depths. Every 30 seconds, the ESP32 reads an analog voltage from each sensor. Capacitive sensors measure the dielectric constant of soil — wetter soil has a higher dielectric constant, producing a lower analog output voltage.
-
DECIDE
The readings are averaged and compared against a calibrated threshold (set during setup for each soil type). If the average moisture level falls below the threshold, the system flags an irrigation event. A hysteresis band prevents rapid on/off cycling.
-
ACT
The ESP32 triggers the relay module, completing the circuit for the water pump. The pump runs for a configurable duration (default: 30 seconds) then pauses, allowing the soil moisture to equalize before re-reading.
-
REPORT
All sensor readings, pump events, and timestamps are logged to the Supabase database via WiFi. The web dashboard displays live charts, historical data, and allows remote threshold adjustment.
WIRING & FIRMWARE
Pin connections and simplified core logic.
// Simplified core logic — Smart Irrigation System
// Full source: github.com/alexcosmasmsoka
#define SENSOR_PIN_1 34
#define SENSOR_PIN_2 35
#define RELAY_PIN 26
#define DRY_THRESHOLD 2800 // calibrate for your soil
#define PUMP_DURATION 30000 // 30 seconds
void loop() {
int avg = readAverageMoisture();
if (avg > DRY_THRESHOLD) {
activatePump(PUMP_DURATION);
logToSupabase("pump_on", avg);
}
logToSupabase("reading", avg);
delay(30000); // read every 30s
}
Full source code available on request or GitHub.
LESSONS LEARNED
What I discovered building and testing this system.
Sensor Calibration is Everything
Each capacitive sensor has a slightly different output range. I spent two days building individual calibration curves for each one. A single shared threshold was producing 30% false readings. Lesson: always calibrate individually.
Hysteresis Prevents Pump Cycling
My first version had the pump switching on/off every 30 seconds as moisture hovered near the threshold. Adding a ±5% hysteresis band (pump on at <40%, off at >50%) completely eliminated this.
WiFi Reliability on 3.3V
The ESP32 WiFi stack is power-hungry. When powering from a weak source, reconnections caused random resets. Adding a 100µF decoupling capacitor on the 3.3V rail and implementing auto-reconnect logic fixed it.
RESULTS
3 weeks of real-world deployment data.
After 3 weeks of deployment in a test garden bed, the Smart Irrigation System delivered consistent results.
BUILD YOUR OWN?
Commission a custom system or follow the build.
Commission a Custom System
Need an irrigation system for your farm or garden? I'll build one tailored to your specific requirements.
Start a Project →MORE PROJECTS
Other systems built at Msoka IoT Lab.
Smart Gate System
Automated gate access control using ESP32, proximity sensors, and a relay-driven motor.
Smart Lamp System
Digitally controlled decorative LED lamp with custom 3D-printed enclosure and app integration.