โ Back to Course
Weather-Based Irrigation Decisions
๐ง Weather-Based Irrigation Decisions
๐ค๏ธ What You'll Learn:
- ๐ Make irrigation decisions based on weather conditions
- ๐ง๏ธ Automatically skip watering when rain is detected
- ๐ก๏ธ Adjust watering duration based on temperature and humidity
- ๐ฐ Save 30-50% more water by factoring in weather forecasts
๐ Decision Matrix Using Weather Data
-
๐ง๏ธ Rain detected in last 6 hours
โ โ Skip irrigation (rain provides natural watering)
๐ง Water saved: 100% of scheduled amount -
๐ก๏ธ Temperature > 35ยฐC + No rain
โ โ ๏ธ Increase watering by 50% (high evaporation)
๐ง Without adjustment: 30-40% water lost to evaporation -
๐จ Humidity < 30% + No rain
โ โ ๏ธ Plants stressed - water immediately + increase duration by 25%
๐ง Low humidity causes rapid transpiration (plants lose water faster) -
๐ค๏ธ Forecast rain + soil moisture > 50%
โ โ Skip irrigation (rain expected soon)
๐ง Prevents over-watering and runoff -
โ ๏ธ Soil moisture < 30% + No rain forecast
โ โ ๏ธ WATER IMMEDIATELY - critical stress level
๐ง Yield loss if delayed: 15-25% reduction
๐ก Weather-Based Savings:
Farmers using weather-based irrigation save an additional 30-50% water compared to soil moisture alone. A 10-acre farm saves 500,000-1,000,000 liters/year by skipping irrigation before rain!
๐ Hardware Setup for Weather Monitoring
- ๐น Rain Sensor (LM393) โ $6 ยท Detects rain/water
- ๐น DHT22 Sensor โ $10 ยท Temperature + humidity
- ๐น Soil Moisture Sensor โ $8 ยท Core soil data
- ๐น Optional: Anemometer โ $25 ยท Wind speed (high wind = more evaporation)
๐ Wiring Diagram (Add Rain Sensor)
ESP32 โ Rain Sensor (LM393)
GPIO35 โ DO (Digital output - rain detected)
3.3V โ VCC
GND โ GND
ESP32 โ DHT22 (Temperature + Humidity)
GPIO15 โ DATA pin
3.3V โ VCC
GND โ GND
ESP32 โ Soil Moisture Sensor
GPIO34 โ AO (analog out)
3.3V โ VCC
GND โ GND
๐ Complete Weather-Based Irrigation Code
#include <DHT.h>
#include <WiFi.h>
#define RELAY_PIN 26
#define SOIL_PIN 34
#define RAIN_PIN 35
#define DHT_PIN 15
DHT dht(DHT_PIN, DHT22);
const unsigned long CHECK_INTERVAL = 1800000; // 30 minutes
// Weather thresholds
const int RAIN_DETECTED = LOW; // Rain sensor output LOW when wet
const float HOT_TEMP = 35.0; // >35ยฐC = increase watering
const float LOW_HUMIDITY = 30.0; // <30% = plant stress
// Soil thresholds
const int DRY_THRESHOLD = 30;
const int OPTIMAL_THRESHOLD = 60;
unsigned long lastCheck = 0;
bool rainDetected = false;
float temperature = 0;
float humidity = 0;
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);
pinMode(RAIN_PIN, INPUT_PULLUP);
digitalWrite(RELAY_PIN, HIGH); // Pump OFF
dht.begin();
Serial.println("๐ค๏ธ Weather-Based Irrigation Started");
}
int getSoilMoisture() {
int raw = analogRead(SOIL_PIN);
return map(raw, 4095, 1500, 0, 100);
}
float getTemperature() {
return dht.readTemperature();
}
float getHumidity() {
return dht.readHumidity();
}
int calculateWateringDuration(int baseMinutes) {
int duration = baseMinutes;
if (rainDetected) {
Serial.println("๐ง๏ธ Rain detected - skipping irrigation");
return 0;
}
if (temperature > HOT_TEMP) {
int extra = baseMinutes * 0.5; // +50% for high heat
duration += extra;
Serial.printf("๐ก๏ธ Hot (%0.1fยฐC) - adding %d min\n", temperature, extra);
}
if (humidity < LOW_HUMIDITY) {
int extra = baseMinutes * 0.25; // +25% for dry air
duration += extra;
Serial.printf("๐จ Low humidity (%0.1f%%) - adding %d min\n", humidity, extra);
}
return min(duration, 30); // Max 30 minutes (fail-safe)
}
void loop() {
unsigned long now = millis();
if (now - lastCheck >= CHECK_INTERVAL) {
lastCheck = now;
// Read all sensors
rainDetected = (digitalRead(RAIN_PIN) == RAIN_DETECTED);
temperature = getTemperature();
humidity = getHumidity();
int moisture = getSoilMoisture();
Serial.println("=================================");
Serial.printf("๐ง๏ธ Rain: %s\n", rainDetected ? "YES" : "NO");
Serial.printf("๐ก๏ธ Temp: %0.1fยฐC\n", temperature);
Serial.printf("๐ง Humidity: %0.1f%%\n", humidity);
Serial.printf("๐ฑ Soil: %d%%\n", moisture);
// Decision logic
if (rainDetected) {
Serial.println("โ
Skipping irrigation (rain provides water)");
}
else if (moisture < DRY_THRESHOLD) {
int duration = calculateWateringDuration(10); // Base 10 min
if (duration > 0) {
Serial.printf("๐ง Watering for %d minutes\n", duration);
digitalWrite(RELAY_PIN, LOW); // Pump ON
delay(duration * 60000);
digitalWrite(RELAY_PIN, HIGH); // Pump OFF
}
}
else if (moisture > OPTIMAL_THRESHOLD) {
Serial.println("โ
Soil moisture optimal - no watering");
}
else {
Serial.println("๐ฟ Soil moisture acceptable - no action");
}
}
}
๐ก Weather API Alternative (No Extra Sensors):
You can get weather data from free APIs instead of adding rain/humidity sensors:
- OpenWeatherMap โ Free tier: 1,000 calls/day
- WeatherAPI.com โ Free tier: 1,000,000 calls/month
- Visual Crossing โ Free tier: 1,000 calls/day
ESP32 connects to WiFi, fetches forecast, and decides to water. No extra hardware needed!
๐ Case Study โ Weather Integration Saves $1,500/Year, South Africa:
A 25-acre maize farm added weather-based decision logic to their existing irrigation system:
- ๐ง๏ธ Rain detection: Skipped 12 irrigation cycles during rainy season
- ๐ฐ Water savings: 850,000 liters saved per year ($1,200)
- โก Energy savings: $300/year in pump electricity
- ๐ Yield impact: 0% loss (perfect moisture maintained)
- ๐ฑ Environmental: Reduced runoff and fertilizer leaching
"Before, I watered every Tuesday whether it rained or not. Now the system checks the weather first. I've cut my water bill in half and my crops are healthier!" โ Farm manager, Free State Province
๐ OceanRemote Automation Rules (Dashboard):
- RULE 1: IF rain_detected = true โ SKIP irrigation cycle
- RULE 2: IF soil_moisture < 30% AND rain_detected = false โ START pump
- RULE 3: IF temperature > 38ยฐC โ Double watering duration
- RULE 4: IF humidity < 25% โ Add 25% to watering time
- RULE 5: IF forecast_rain_next_6h = true AND soil_moisture > 50% โ SKIP
โ ๏ธ Important Notes:
- Rain sensors can false-trigger from morning dew โ add a 1-hour delay before skipping
- High wind (>20km/h) increases evaporation by 30-50% โ consider wind sensor for accuracy
- Always keep a minimum watering schedule (e.g., at least once per 5 days) as fail-safe
- Weather API requires WiFi โ ensure your ESP32 has reliable connection
๐ฏ Key Takeaways:
- โ Weather-based irrigation saves 30-50% MORE water than soil moisture alone
- โ Rain sensors or weather APIs prevent over-watering before storms
- โ High temperature (+50% water) and low humidity (+25% water) require adjustments
- โ A $6 rain sensor pays for itself in 1-2 months through water savings
- โ Always use fail-safe timers โ never trust sensors 100%
- โ Combine soil + weather data for optimal irrigation decisions
๐ก Key Takeaways:
- Apply these concepts directly to your farm or project.
- Take notes on important details for the quiz.
- Use the button below to track your progress.
×