Projects / Leaf wetness sensor for disease warning

Leaf wetness sensor for disease warning

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Make the comb

    Cut alternate stripboard tracks into two interlocking sets.

  2. NANO

    Solder the wires

    One per comb, with long leads.

  3. NANO

    Wire the divider

    100 k from A0 to GND.

  4. NANO

    Find the threshold

    Read A0 dry and wet.

  5. NANO

    Upload and test

    Breathe on the comb and watch the count.

  6. NANO12.9 mA

    Install in the field

    Angled at crop height.

  7. NANO

    Check the log after a dewy night

    Wet minutes at dawn.

  8. NANO

    Replace the comb

    When readings drift.

In short

How do you build a leaf wetness sensor for disease warning?

A comb-pattern sensor imitates a leaf and measures how long it stays wet with dew, the main factor in fungal disease on crops. You need Arduino Nano, Stripboard (Veroboard) 10 × 10 cm, Resistor 100 kΩ, MicroSD Card Module, DS3231 RTC module, LED 5 mm red, Resistor 330 Ω and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 120 minutes.

Level
Intermediate
Time
About 120 min
Parts
8

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Comb sensor, side ANano D7Drive pin, powered only while reading
Comb sensor, side BNano A0, and 100 k from A0 to GNDVoltage divider reading
DS3231 SDA and SCLNano A4 and A5Real-time clock
DS3231 VCC and GNDNano 5V and GNDPower
SD module CS, MOSI, MISO, SCKNano D10, D11, D12, D13Storage
SD module VCC and GNDNano 5V and GNDPower
Warning LEDNano D4 through 330 Ω to GNDWet more than 6 hours

Code

Leaf diseases such as blight and mildew grow when leaves stay wet for hours, so growers track wet time. This sensor is two interlocking combs of copper track on stripboard: cut every other track to make two separate sets of fingers, or draw a comb on a small PCB. When dew or rain bridges the gap the resistance drops and the voltage on A0 rises. The comb is powered from a digital pin only for five milliseconds each minute because a constantly powered, wet comb corrodes within days; a coat of clear lacquer on one face also helps, and you should expect to replace the sensor each season. Dip the comb in water and note A0, then dry it and note again, and set WET_THRESHOLD between them. Mount the sensor facing up at about 45 degrees, at crop height in the shade of the canopy, and shield the electronics in a box. The sketch counts wet minutes in the day, logs every ten minutes and writes the total at midnight. After six continuous hours the LED warns that conditions suit fungus; spray timing should still follow local agricultural advice, as this is an indicator, not an expert system. Setup: Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails). Install RTClib.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>

const uint8_t PIN_DRIVE = 7, PIN_SENSE = A0, SD_CS = 10, LED_PIN = 4;
const int WET_THRESHOLD = 150;                // 0 to 1023, tune it by dipping the comb in water
const unsigned int ALERT_WET_MIN = 360;       // 6 hours of continuous wetness
const unsigned long SAMPLE_MS = 60000UL;      // one reading a minute

RTC_DS3231 rtc;
unsigned int wetToday = 0, streak = 0, minutes = 0;
int lastDay = -1;
unsigned long lastSample = 0;

int readLeaf() {
  digitalWrite(PIN_DRIVE, HIGH);      // power the comb only while measuring, to slow corrosion
  delay(5);
  int v = analogRead(PIN_SENSE);
  digitalWrite(PIN_DRIVE, LOW);
  return v;
}

void logLine(const char *tag, int raw, bool wet, unsigned int total) {
  DateTime n = rtc.now();
  File f = SD.open("leaf.csv", FILE_WRITE);
  if (!f) return;
  f.print(n.timestamp()); f.print(',');
  f.print(tag); f.print(',');
  f.print(raw); f.print(',');
  f.print(wet ? 1 : 0); f.print(',');
  f.println(total);
  f.close();
}

void setup() {
  pinMode(PIN_DRIVE, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(PIN_DRIVE, LOW);
  Serial.begin(9600);
  rtc.begin();
  SD.begin(SD_CS);
  lastDay = rtc.now().day();
}

void loop() {
  if (millis() - lastSample < SAMPLE_MS) return;
  lastSample = millis();
  DateTime n = rtc.now();
  if (n.day() != lastDay) {              // a new day: save the total and reset
    logLine("DAY_TOTAL", 0, false, wetToday);
    wetToday = 0; streak = 0; lastDay = n.day();
  }
  int raw = readLeaf();
  bool wet = raw > WET_THRESHOLD;
  if (wet) { wetToday++; streak++; } else streak = 0;
  digitalWrite(LED_PIN, streak >= ALERT_WET_MIN ? HIGH : LOW);
  minutes++;
  if (minutes % 10 == 0) logLine("SAMPLE", raw, wet, wetToday);
  Serial.print(raw); Serial.print(' '); Serial.println(wetToday);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Dry combA0 near 0
Wet fingertip across the combsRaw value rises above the threshold
Hold it wet for a minuteWet minutes increase by one
Leave it overnight outdoorsWet minutes appear around dawn
Set ALERT to 2 for a testLED lights after two wet minutes

If it does not work

Always wet

Combs touching, or flux or dirt bridging the tracks; clean with isopropyl alcohol.

Never wet

Threshold too high, or the drive pin is not connected.

Readings creep up over days

Corrosion; replace the comb and lacquer it.

No SD lines

Card format or CS pin; the sketch carries on without it.

Wrong day totals

Set the RTC with the RTClib example first.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the leaf wetness sensor for disease warning?

Arduino Nano, Stripboard (Veroboard) 10 × 10 cm, Resistor 100 kΩ, MicroSD Card Module, DS3231 RTC module, LED 5 mm red, Resistor 330 Ω and Jumper wires male to male (40 pcs, 20 cm).

How long does the leaf wetness sensor for disease warning take to build?

About 120 minutes for a intermediate maker, in 8 steps.

How do I know the leaf wetness sensor for disease warning works?

Dry comb: A0 near 0. Wet fingertip across the combs: Raw value rises above the threshold. Hold it wet for a minute: Wet minutes increase by one.

Always wet: what should I check?

Combs touching, or flux or dirt bridging the tracks; clean with isopropyl alcohol.

Never wet: what should I check?

Threshold too high, or the drive pin is not connected.

Readings creep up over days: what should I check?

Corrosion; replace the comb and lacquer it.

No SD lines: what should I check?

Card format or CS pin; the sketch carries on without it.