A leaf wetness sensor fungal disease prevention system can protect your crops from devastating fungal infections like powdery mildew, downy mildew, and early blight before they spread. By monitoring moisture on leaf surfaces in real time, you can automate fungicide spraying and improve farm productivity dramatically. This guide covers building a complete automated fungal disease prevention system using leaf wetness sensors, ESP32, and relay-controlled sprayers.
Table of Contents
- Why Leaf Wetness Matters for Disease Prevention
- How Leaf Wetness Sensors Work
- Components Required
- Circuit and Wiring
- ESP32 Arduino Code
- Fungal Disease Models and Thresholds
- Automated Sprayer Integration
- Indian Farm Applications
- Frequently Asked Questions
Why Leaf Wetness Matters for Disease Prevention
Fungal diseases require two conditions to thrive: suitable temperature and moisture on the leaf surface. Most fungal pathogens need the leaf to remain wet for 4–12 hours at temperatures between 15°C and 30°C to complete their infection cycle. In India, monsoon season and high-humidity regions like Maharashtra, Kerala, and West Bengal create ideal conditions for diseases such as:
- Late blight (Phytophthora infestans) on tomato and potato
- Powdery mildew on grapes, cucumber, and wheat
- Downy mildew on pearl millet (bajra)
- Brown spot on rice paddy
- Anthracnose on mango and chilli
By monitoring leaf wetness duration, you can apply the Wallin model or similar disease severity indices (DSI) to predict infection risk and spray only when necessary — reducing fungicide use by 40–60% compared to calendar-based spraying.
How Leaf Wetness Sensors Work
Leaf wetness sensors measure electrical conductance across interdigitated electrodes on a flat substrate. When water droplets bridge the electrodes, conductance increases, producing a higher analogue voltage output. The sensor surface is typically coated with a paint that mimics leaf surface properties.
Common types used in India:
- Resistive leaf wetness sensor — Simple, low cost, analogue output 0–3.3V
- Capacitive leaf wetness sensor — More accurate, less prone to contamination
- SHT10/SHT11 with RH threshold — Uses relative humidity as proxy for dew formation
For this project, a resistive analogue sensor is used with the ESP32’s ADC. A value above a calibrated threshold (typically 2000–2500 on a 12-bit ADC) indicates wet conditions.
Components Required
Recommended Products from Zbotic
- YL-69 Soil Moisture Sensor (analogue output, works as leaf wetness sensor) — ₹49
- Capacitive Soil Moisture Sensor v1.2 — ₹129 (capacitive, more durable)
- GY-BME280 Temperature Humidity Sensor 3.3V — for ambient RH and temperature monitoring
- 5V 12V Soil Moisture Sensor Relay Control Module — for automatic pump/sprayer trigger
Full parts list:
- ESP32 development board
- Leaf wetness / soil moisture sensor (analogue)
- BME280 temperature and humidity sensor
- 4-channel relay module (5V)
- 12V solenoid valve or peristaltic pump for sprayer
- 12V DC power supply (2A)
- DS3231 RTC module for accurate timestamps
- Jumper wires, project box
Circuit and Wiring
Connect components as follows:
- Leaf wetness sensor AOUT → ESP32 GPIO34 (ADC1_CH6)
- BME280 SDA → GPIO21, SCL → GPIO22
- Relay IN1 → GPIO26 (sprayer control)
- Relay IN2 → GPIO27 (alert buzzer)
- Relay COM → 12V+, NO → solenoid valve+
- Power: 5V to relay and sensors, 3.3V to ESP32 from onboard regulator
Mount the leaf wetness sensor at canopy level, positioned horizontally on a wooden stake at the same height as the crop leaves. Orient it at a 45° angle in the direction of prevailing wind to match natural leaf wetting behaviour.
ESP32 Arduino Code
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <time.h>
const char* ssid = "FarmWiFi";
const char* password = "your_password";
const char* thingspeakKey = "YOUR_THINGSPEAK_KEY";
Adafruit_BME280 bme;
#define LEAF_WET_PIN 34
#define SPRAY_RELAY 26
#define ALERT_RELAY 27
// Leaf wetness thresholds (12-bit ADC, 0-4095)
const int WET_THRESHOLD = 2200; // Above = wet leaf
const int DRY_THRESHOLD = 1500; // Below = dry leaf
// Disease Severity Index (Wallin model simplified)
int wetHours = 0;
int dsiScore = 0;
bool leafWet = false;
unsigned long lastHourCheck = 0;
bool sprayerActive = false;
void setup() {
Serial.begin(115200);
pinMode(SPRAY_RELAY, OUTPUT);
pinMode(ALERT_RELAY, OUTPUT);
digitalWrite(SPRAY_RELAY, HIGH); // Relay off (active LOW)
digitalWrite(ALERT_RELAY, HIGH);
Wire.begin(21, 22);
if (!bme.begin(0x76)) {
Serial.println("BME280 not found!");
}
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("
WiFi connected");
configTime(19800, 0, "pool.ntp.org"); // IST = UTC+5:30
}
void loop() {
int rawADC = analogRead(LEAF_WET_PIN);
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
// Determine leaf wetness state
bool currentlyWet = (rawADC > WET_THRESHOLD);
// Track wetness hours (check every 60 minutes)
unsigned long now = millis();
if (now - lastHourCheck >= 3600000UL) {
lastHourCheck = now;
if (currentlyWet) {
wetHours++;
} else {
wetHours = max(0, wetHours - 1); // Dry hours reduce counter
}
// Update DSI based on temperature + wet hours (simplified Wallin)
updateDSI(temperature, wetHours);
}
leafWet = currentlyWet;
// Trigger spray if DSI exceeds threshold
if (dsiScore >= 7 && !sprayerActive) {
activateSprayer();
}
Serial.printf("ADC: %d | Wet: %s | Temp: %.1f°C | RH: %.1f%% | WetHrs: %d | DSI: %d
",
rawADC, currentlyWet ? "YES" : "NO", temperature, humidity, wetHours, dsiScore);
// Upload to ThingSpeak every 15 minutes
static unsigned long lastUpload = 0;
if (now - lastUpload >= 900000UL) {
uploadData(rawADC, temperature, humidity, wetHours, dsiScore);
lastUpload = now;
}
delay(60000); // Check every minute
}
void updateDSI(float temp, int wetHrs) {
// Simplified Wallin DSI: accumulate infection risk points
// High risk: 18-22°C + wet >6 hrs
int riskPoints = 0;
if (temp >= 10 && temp < 15) riskPoints = (wetHrs >= 12) ? 3 : (wetHrs >= 9) ? 2 : 1;
else if (temp >= 15 && temp < 20) riskPoints = (wetHrs >= 6) ? 4 : (wetHrs >= 4) ? 3 : 1;
else if (temp >= 20 && temp < 25) riskPoints = (wetHrs >= 6) ? 4 : (wetHrs >= 4) ? 3 : 2;
else if (temp >= 25 && temp < 30) riskPoints = (wetHrs >= 9) ? 3 : (wetHrs >= 6) ? 2 : 1;
dsiScore += riskPoints;
if (dsiScore > 10) dsiScore = 10; // Cap at 10
}
void activateSprayer() {
sprayerActive = true;
digitalWrite(SPRAY_RELAY, LOW); // Activate sprayer
digitalWrite(ALERT_RELAY, LOW); // Alert buzzer
Serial.println("ALERT: High disease risk - sprayer activated!");
delay(30000); // Spray for 30 seconds
digitalWrite(SPRAY_RELAY, HIGH);
digitalWrite(ALERT_RELAY, HIGH);
sprayerActive = false;
dsiScore = 0; // Reset DSI after treatment
wetHours = 0;
}
void uploadData(int adc, float temp, float hum, int wetHrs, int dsi) {
if (WiFi.status() != WL_CONNECTED) return;
HTTPClient http;
String url = "http://api.thingspeak.com/update?api_key=" + String(thingspeakKey);
url += "&field1=" + String(adc);
url += "&field2=" + String(temp, 1);
url += "&field3=" + String(hum, 1);
url += "&field4=" + String(wetHrs);
url += "&field5=" + String(dsi);
http.begin(url);
http.GET();
http.end();
}
Fungal Disease Models and Thresholds
The code implements a simplified version of the Wallin Disease Severity Index (DSI), widely used in precision agriculture for late blight forecasting. The DSI accumulates infection risk points based on temperature ranges and consecutive wet hours:
| Temperature Range | Wet Hours for Infection | DSI Points/Day |
|---|---|---|
| 10–15°C | 12+ hours | 3 |
| 15–20°C | 6+ hours | 4 |
| 20–25°C | 6+ hours | 4 (optimal) |
| 25–30°C | 9+ hours | 3 |
When DSI reaches 7, an immediate fungicide spray is triggered. A DSI of 10 (maximum) indicates imminent epidemic conditions requiring emergency intervention.
Automated Sprayer Integration
The relay module drives a 12V solenoid valve connected to your existing pump-and-pipe irrigation system. For foliar spray, use a nozzle pressure of 2–3 bar to achieve fine droplet distribution (150–250 micron VMD) for good canopy coverage.
Advanced integration options:
- Telegram bot alerts: Send DSI warnings to farmer’s mobile via Telegram API
- Multiple zones: Use 4-channel relay to control different field sections independently
- GSM backup: SIM800L for SMS alerts when WiFi is unavailable in remote fields
- Solar power: 10W solar panel + 7Ah battery for off-grid operation
Sprayer and Pump Products
- 12V DC Mini Submersible Water Pump — ₹199 (for small spray setups)
- Relay Control Module (5V/12V) — ₹89 (direct leaf wetness trigger)
- Raindrops Detection Sensor Module — ₹49 (detect rain to pause spraying)
Indian Farm Applications
In India, this system is particularly valuable for:
- Grape farms (Nashik, Sangli): Downy mildew causes 30–70% crop loss during monsoon. DSI-based spraying reduces fungicide applications from 20+ to 8–10 per season.
- Tomato and potato (Punjab, UP, Bihar): Late blight warning systems save ₹8,000–15,000/acre in lost produce during high-humidity periods.
- Tea gardens (Darjeeling, Assam): Blister blight monitoring throughout the flush season.
- Apple orchards (Himachal Pradesh, J&K): Scab and fire blight prevention during the wet spring months.
The system integrates with e-NAM and state agricultural advisory services like mKisan for government-supported disease advisory alerts.
Frequently Asked Questions
Can I use a YL-69 soil moisture sensor as a leaf wetness sensor?
Yes, the YL-69 (resistive type) works well as an inexpensive leaf wetness sensor when mounted horizontally at canopy level. Clean the electrodes weekly to prevent false readings from soil contamination. The capacitive version lasts longer in field conditions.
What is the difference between leaf wetness and humidity sensors?
Relative humidity measures water vapour in the air, while leaf wetness directly detects liquid water on the leaf surface. A field can have 70% RH with no leaf wetness, or 85% RH with heavy dew. Direct leaf wetness sensing is 3–5x more accurate for disease prediction models.
How many sensors do I need per acre?
For flat fields, one sensor per 2–3 acres is sufficient. In hilly terrain or orchards with varying canopy density, use one sensor per 1 acre. Position sensors in the most disease-prone microclimate (usually low-lying, shaded areas with poor air circulation).
How do I prevent false triggers from rain vs. pathogenic wetness?
Add a rain sensor (tipping bucket or resistive) to the system. When rainfall is detected, pause the DSI accumulation and do not trigger sprayers (spraying during rain is wasteful). Resume monitoring 30 minutes after rain stops.
What fungicides can be applied automatically?
Contact fungicides like Mancozeb, Chlorothalonil, and Copper-based formulations are suitable for automatic application as they are relatively safe. Systemic fungicides (Metalaxyl, Cymoxanil) should be applied manually after farmer confirmation due to resistance management concerns.
Add comment