Build it step by step
0 of 7 doneWire the module
GND to GND, VCC to GPIO5, AO to GPIO2.
Connect the plate
Two-wire lead to the module's sensor pins.
Wire the buzzer
GPIO4 and GND.
Upload the sketch
Open the Serial Monitor at 115200, the dry level prints.
Spray a little water on the plate
After two seconds three beeps sound.
Dry the plate
After a minute the alert resets.
Mount it
Plate outside and tilted, electronics dry indoors.
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
| From | To | Why |
|---|---|---|
| Rain module VCC | ESP32-C3 SuperMini GPIO5 | Powered only while reading, so the plate corrodes less |
| Rain module GND | ESP32-C3 SuperMini GND | Common ground |
| Rain module AO | ESP32-C3 SuperMini GPIO2 | Analog reading, falls when wet |
| Rain plate | Rain module sensor pins | The two-wire lead to the plate |
| Buzzer + | ESP32-C3 SuperMini GPIO4 | Alert sound |
| Buzzer - | ESP32-C3 SuperMini GND | Ground |
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.
| Check | Expected |
|---|---|
| Dry plate | No sound |
| One splash | No sound |
| Water on the plate for two seconds | Three beeps |
| Plate stays wet | Beeps again each minute |
| Plate dry for one minute | Alert 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 →
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.
