Predictive Agriculture: IoT Irrigation
A standard moisture sensor just turns on the water when the dirt is dry. But what if a massive thunderstorm is arriving in 30 minutes? You just wasted gallons of water! The Smart Weather-Based Irrigation System uses internet predictions to act intelligently.

The JSON API Request
The ESP8266 (NodeMCU) is the absolute requirement for this project.
- The ESP connects to your home Wi-Fi.
- It sends an HTTP GET request to
OpenWeatherMap.orgAPI for your specific zip code. - The server replies with a dictionary string (JSON data).
- The ESP uses the
ArduinoJsonlibrary to extract today's predicted rainfall percentage (e.g.,"pop": 0.85, meaning 85% chance of rain).
The Decision Tree Logic
The code fuses physical sensor data with the virtual forecast data:
- It reads the local dirt via an Analog Soil Moisture Sensor.
Result: DRY. - It checks the API data:
Chance of Rain: 85%. - The Override:
if (moisture < 300 && chanceOfRain < 50)-> Turn on the water. Because the chance of rain is 85%, the logic tree aborts the watering sequence! It knows nature will water the plants shortly.
Hardware Control Variables
- ESP8266 NodeMCU or ESP32: The Wi-Fi API client.
- Corrosion-Resistant Capacitive Soil Moisture Sensor v1.2 (Do NOT use the cheap exposed-metal resistive prongs, they will dissolve in the dirt).
- 12V Water Solenoid Valve: Connected to a garden hose.
- 5V Relay Module & 12V Power Adapter: To actuate the heavy valve based on the ESP's 3.3V signals.