Projects / ESP32-C3 rain alert

ESP32-C3 rain alert

Beginner1.8 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Wire the module

    GND to GND, VCC to GPIO5, AO to GPIO2.

  2. ESP32

    Connect the plate

    Two-wire lead to the module's sensor pins.

  3. ESP32

    Wire the buzzer

    GPIO4 and GND.

  4. ESP32

    Upload the sketch

    Open the Serial Monitor at 115200, the dry level prints.

  5. ESP32

    Spray a little water on the plate

    After two seconds three beeps sound.

  6. ESP32

    Dry the plate

    After a minute the alert resets.

  7. ESP32

    Mount it

    Plate outside and tilted, electronics dry indoors.

In short

How do you build an ESP32-C3 rain alert?

An ESP32-C3 SuperMini reads a rain drop sensor plate and sounds a short buzzer pattern when rain falls on it, a reminder to bring in the washing. You need ESP32-C3 SuperMini, Rain drop sensor module, Active buzzer 5 V and Breadboard 830 Tie Points. It takes 7 steps and about 110 minutes.

Level
Beginner
Time
About 110 min
Parts
4

Parts list

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

Wiring

FromToWhy
Rain module VCCESP32-C3 SuperMini GPIO5Powered only while reading, so the plate corrodes less
Rain module GNDESP32-C3 SuperMini GNDCommon ground
Rain module AOESP32-C3 SuperMini GPIO2Analog reading, falls when wet
Rain plateRain module sensor pinsThe two-wire lead to the plate
Buzzer +ESP32-C3 SuperMini GPIO4Alert sound
Buzzer -ESP32-C3 SuperMini GNDGround

Code

A rain drop sensor is a board of bare copper tracks that are not connected to each other. A dry board has a very high resistance between the tracks, and a water drop bridges them, so the voltage at the module's analog output drops. The program measures the reading when the board is dry, at start-up, and decides it is raining when the reading falls by a good margin for two seconds, which ignores a single splash. It then sounds three short beeps, and repeats the reminder once a minute until the plate has been dry for a minute. Water on powered copper causes it to corrode quickly, so the module's power comes from a pin that is switched on for only twenty milliseconds at each reading. Keep the plate outside and slightly tilted so drops run off, and keep the electronics inside, dry, with only the thin lead going out through a gap in a window.

Runs on a virtual ESP32-C3 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).

const int SENSOR_POWER = 5;
const int SENSOR_PIN = 2;
const int BUZZER = 4;

int dryLevel = 4095;
int wetLevel = 3000;
bool raining = false;
unsigned long wetSince = 0, drySince = 0, lastBeep = 0;

int readSensor() {
  digitalWrite(SENSOR_POWER, HIGH);               // power the plate only while measuring
  delay(20);
  int v = analogRead(SENSOR_PIN);
  digitalWrite(SENSOR_POWER, LOW);
  return v;
}

void beepPattern() {
  for (int i = 0; i < 3; i++) {
    digitalWrite(BUZZER, HIGH); delay(120);
    digitalWrite(BUZZER, LOW);  delay(120);
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(SENSOR_POWER, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  analogReadResolution(12);
  delay(500);
  long total = 0;
  for (int i = 0; i < 10; i++) { total += readSensor(); delay(50); }
  dryLevel = total / 10;                           // start with the plate dry
  wetLevel = dryLevel - 700;                       // a drop of at least this much counts as wet
  Serial.print("Dry level "); Serial.println(dryLevel);
}

void loop() {
  int v = readSensor();
  unsigned long now = millis();
  bool wet = v < wetLevel;

  if (wet) {
    drySince = 0;
    if (wetSince == 0) wetSince = now;
    if (!raining && now - wetSince > 2000) {       // wet for two seconds counts as rain
      raining = true;
      beepPattern();
      lastBeep = now;
    }
    if (raining && now - lastBeep > 60000) {       // remind once a minute
      beepPattern();
      lastBeep = now;
    }
  } else {
    wetSince = 0;
    if (drySince == 0) drySince = now;
    if (raining && now - drySince > 60000) raining = false;   // dry for a minute ends it
  }
  delay(500);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32-C3 DevKitM-1 with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Dry level 2048

Test checklist

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

CheckExpected
Dry plateNo sound
One splashNo sound
Water on the plate for two secondsThree beeps
Plate stays wetBeeps again each minute
Plate dry for one minuteAlert resets

If it does not work

Beeps on its own

Raise the wetLevel margin, the dry reading may be noisy.

Never beeps

Check AO is on GPIO2 and VCC on GPIO5, and read the value in the Serial Monitor.

Reading does not change when wet

Check the plate lead is firmly connected.

Plate tracks look green or eaten

Corrosion, replace the plate and keep the power switching.

No sound

Check the buzzer direction and that it is an active buzzer.

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

Ask Lark AI

Common questions

What parts do I need for the ESP32-C3 rain alert?

ESP32-C3 SuperMini, Rain drop sensor module, Active buzzer 5 V and Breadboard 830 Tie Points.

How long does the ESP32-C3 rain alert take to build?

About 110 minutes for a beginner maker, in 7 steps.

How do I know the ESP32-C3 rain alert works?

Dry plate: No sound. One splash: No sound. Water on the plate for two seconds: Three beeps.

Beeps on its own: what should I check?

Raise the wetLevel margin, the dry reading may be noisy.

Never beeps: what should I check?

Check AO is on GPIO2 and VCC on GPIO5, and read the value in the Serial Monitor.

Reading does not change when wet: what should I check?

Check the plate lead is firmly connected.

Plate tracks look green or eaten: what should I check?

Corrosion, replace the plate and keep the power switching.