What if the soil could talk? An ESP32 reads soil moisture, temperature and humidity, decides when to water using hysteresis control, publishes everything over MQTT, and a live browser dashboard lets you watch — and switch the pump from anywhere.
Built and tested entirely in the Wokwi simulator — no hardware needed to try it. By Ajay Chowdary Uppalapati, B.Sc. Horticulture.
| 📡 Live telemetry | Moisture, temperature, humidity and pump state every 2 s over MQTT |
| 🧮 Smart averaging | 10 ADC samples per reading smooth out sensor noise |
| 🎯 Hysteresis control | ON below 30 %, OFF above 45 % — the pump never flickers |
| 🛡️ Safety first | 10 s maximum run + 5 s cool-down in every mode |
| 🎛️ Remote control | Switch auto/manual, run the pump, change thresholds from the dashboard |
| 🖥️ Dashboard | Gauges, history chart, event log, animated field scene, built-in demo mode |
flowchart LR
S["🌱 Soil sensor<br/>GPIO34"] --> E
D["🌡️ DHT22<br/>GPIO4"] --> E
E{{"ESP32<br/>average · decide"}} -->|GPIO26| P["💧 Relay + pump"]
E -- "…/data (JSON, 2 s)" --> B(("HiveMQ<br/>MQTT broker"))
B -- "…/cmd" --> E
B <-->|WebSocket| W["🖥️ Live dashboard"]
smart-irrigation-esp32/
├── firmware/
│ └── smart_irrigation_v2.ino # ESP32 firmware (Arduino C++)
├── dashboard/
│ └── irrigation_dashboard_v3.html # Single-file live dashboard
├── docs/
│ ├── setup-guide.md # Run it in 5 minutes
│ ├── how-it-works.md # Control loop explained
│ ├── mqtt-topics.md # Topics, JSON, commands
│ ├── hardware.md # Wiring & parts list
│ └── assets/ # Animated SVGs, GIF, screenshots
├── wokwi/
│ ├── diagram.json # Simulator circuit
│ └── libraries.txt
├── index.html # Animated project page (GitHub Pages)
├── LICENSE # MIT
└── README.md
- Simulate — follow the setup guide: paste the firmware into a new Wokwi ESP32 project and press ▶.
- Watch — open the dashboard (add
?demo=1to try it without a device). - Control — switch to manual and run the pump from the dashboard, or from a terminal:
mosquitto_pub -h broker.hivemq.com -t smartirrigation/ajay4821/cmd -m "pump:on"| Part | GPIO |
|---|---|
| Soil moisture sensor (analog) — potentiometer in Wokwi | 34 |
| DHT22 temperature + humidity | 4 |
| Relay → pump — LED in Wokwi | 26 |
![]() |
![]() |
![]() |
![]() |
The default setup uses the public HiveMQ broker with no authentication. Anyone who knows the topic can read the data and send pump commands.
Change the ajay4821 topic id to something unique before sharing, and use a private broker with TLS + credentials for real hardware.
Details in the setup guide.
- FreeRTOS tasks for sensing / control / networking
- Real hardware build with capacitive sensor and relay
- Solar power with battery monitoring
- Private broker with TLS and authentication
- Rain forecast integration
MIT © 2026 Ajay Chowdary Uppalapati
If this helped you, drop a ⭐ — and tell me what you'd build next.




