Build a Wemos D1 Mini rain detector with a YL-83 sensor, buzzer and LED alarm, plus a Wi-Fi page showing DRY/WET. Wiring table, diagram and full code.
Need it ready-made? Buy Ready Project

This Wemos D1 Mini rain detector tells you the moment rain starts to fall. A cheap YL-83 / FC-37 rain pad sits outside, the Wemos D1 Mini (ESP8266) reads it, and an active buzzer and a red LED come on as soon as the pad gets wet. The board also joins your home Wi-Fi and serves a small status page, so you can open it on your phone and see DRY or WET together with the live analog reading.
It is a small, beginner-friendly build: four parts, a handful of jumper wires and one sketch. It is handy for reminding you to bring the washing in, closing a skylight by hand before the storm, or as the first block of a bigger weather station.
How the Rain Detector Works
The rain pad is a board with two interleaved copper tracks. When it is dry the tracks are not connected, so the resistance between them is very high. A drop of water bridges the tracks and the resistance falls. The more water on the pad, the lower the resistance.
The small control module that comes with the pad has an LM393 comparator and a sensitivity potentiometer. It gives you two outputs:
- AO (analog output): a voltage that falls as the pad gets wetter. The Wemos reads it on A0, its only analog input, as a number from 0 to 1023. A dry pad reads close to 1024; a wet pad reads much lower.
- DO (digital output): the comparator output. It is HIGH when dry and goes LOW when wet. The trip point is set with the blue potentiometer, and the module’s DO LED lights when it trips. The Wemos reads it on D5 (GPIO14).
The sketch treats the pad as wet if DO is LOW or the analog value falls below a threshold (600 by default). It only goes back to dry when DO is HIGH and the analog value is above 700. That gap (hysteresis) stops the alarm flickering while the pad slowly dries. When it is wet, the LED on D7 (GPIO13) stays on and the active buzzer on D6 (GPIO12) beeps on and off without blocking the web server.
At the same time the ESP8266 runs a tiny web server on port 80. The main page shows the state in a green or red box with the A0 reading and refreshes every three seconds. A second address, /json, returns the same data for apps or home-automation tools.
Components Required
- Wemos D1 Mini (ESP8266) – 1
- Rain / water-drop sensor kit (YL-83 or FC-37 pad with LM393 module) – 1
- Active buzzer, 3.3 V type (or a 3–5 V active buzzer module with an I/O pin) – 1
- Red LED, 5 mm – 1
- 330 Ω resistor – 1
- Jumper wires (female-female for the module, male-male for a breadboard)
- Breadboard (optional) and a micro-USB cable
- Power: USB phone charger into the D1 Mini, or a regulated 5 V supply on the 5V pin
Wiring Table (Pin-to-Pin)
| Part | Part Pin | Wemos D1 Mini Pin | GPIO | Notes |
|---|---|---|---|---|
| Rain module | VCC | 3V3 | — | Use 3.3 V. ESP8266 inputs are 3.3 V logic, so a 5 V supply would push DO above a safe level |
| Rain module | GND | G | — | Common ground |
| Rain module | AO | A0 | ADC0 | The only analog input. The D1 Mini A0 accepts 0–3.2 V |
| Rain module | DO | D5 | GPIO14 | LOW = wet, HIGH = dry. Set the trip point with the module pot |
| Rain pad | Two pins | Rain module input pins | — | Polarity does not matter |
| Active buzzer | + (long leg) | D6 | GPIO12 | HIGH = sound. Use a module or an NPN transistor for a loud 5 V buzzer |
| Active buzzer | − | G | — | Common ground |
| Red LED | Anode (long leg) | D7 through 330 Ω | GPIO13 | About 4 mA, safe for the pin |
| Red LED | Cathode (short leg) | G | — | Common ground |
| Power | USB or 5 V | Micro-USB / 5V pin | — | The on-board regulator makes 3.3 V |
Avoid D3 (GPIO0), D4 (GPIO2) and D8 (GPIO15) for the sensor and buzzer in this build. Those pins decide how the ESP8266 boots, and a part that pulls them the wrong way can stop the board from starting. D5, D6 and D7 have no boot role, so they are a safe choice.
A single ESP8266 pin can only supply about 12 mA. A small 3.3 V active buzzer works directly. If your buzzer is a louder 5 V type, buy a buzzer module with its own transistor (VCC, GND and I/O pins), or drive it through a 2N2222 / BC547 with a 1 kΩ base resistor from D6.
Connection Diagram
The labelled diagram below matches the wiring table. All ground symbols are one common ground and go to the Wemos G pin.
Arduino Code for the Wemos D1 Mini
Install the ESP8266 board package in the Arduino IDE (Boards Manager → esp8266 by ESP8266 Community) and select LOLIN(WEMOS) D1 R2 & mini. The sketch only uses libraries that come with that package. Replace YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with your own network before uploading.
/*
Wemos D1 Mini Rain Detector with Buzzer, LED and Wi-Fi Status Page
------------------------------------------------------------------
Board : LOLIN(WEMOS) D1 R2 & mini (ESP8266 Arduino core)
Sensor : YL-83 / FC-37 rain pad + LM393 comparator module
Wiring (see the wiring table in the article):
Module VCC -> 3V3 Module GND -> G
Module AO -> A0 (ADC) Module DO -> D5 (GPIO14)
Buzzer + -> D6 (GPIO12), Buzzer - -> G
LED anode -> 330 ohm -> D7 (GPIO13), LED cathode -> G
Open the Serial Monitor at 115200 baud to see the IP address,
then browse to http://<that-ip>/ (JSON at http://<that-ip>/json)
*/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// ---------- Wi-Fi credentials: replace with your own ----------
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
// ---------- Pins (Wemos label = GPIO number) ----------
const uint8_t PIN_RAIN_AO = A0; // analog output of the module (only ADC)
const uint8_t PIN_RAIN_DO = D5; // GPIO14, LOW when the pad is wet
const uint8_t PIN_BUZZER = D6; // GPIO12, active buzzer (HIGH = sound)
const uint8_t PIN_LED = D7; // GPIO13, LED through 330 ohm
// ---------- Tuning ----------
// The analog value falls as the pad gets wetter (about 1024 dry, lower when wet).
const int WET_THRESHOLD = 600; // below this = wet
const int DRY_THRESHOLD = 700; // above this = dry again (hysteresis)
const unsigned long READ_INTERVAL_MS = 500;
const unsigned long BEEP_ON_MS = 200;
const unsigned long BEEP_OFF_MS = 800;
ESP8266WebServer server(80);
int rainAnalog = 1024;
bool rainDigitalWet = false;
bool isWet = false;
unsigned long lastRead = 0;
unsigned long lastBeepChange = 0;
bool buzzerOn = false;
unsigned long wetSince = 0;
// Read the sensor and decide DRY or WET
void readSensor() {
rainAnalog = analogRead(PIN_RAIN_AO); // 0..1023
rainDigitalWet = (digitalRead(PIN_RAIN_DO) == LOW); // module DO goes LOW when wet
bool newWet = isWet;
if (rainDigitalWet || rainAnalog < WET_THRESHOLD) {
newWet = true;
} else if (!rainDigitalWet && rainAnalog > DRY_THRESHOLD) {
newWet = false;
}
if (newWet && !isWet) {
wetSince = millis();
Serial.println(F("Rain detected!"));
} else if (!newWet && isWet) {
Serial.println(F("Pad is dry again."));
}
isWet = newWet;
Serial.printf("A0=%d DO=%s state=%s\n", rainAnalog,
rainDigitalWet ? "WET" : "DRY", isWet ? "WET" : "DRY");
}
// Beep on/off without blocking the web server
void updateAlarm() {
digitalWrite(PIN_LED, isWet ? HIGH : LOW);
if (!isWet) {
buzzerOn = false;
digitalWrite(PIN_BUZZER, LOW);
return;
}
unsigned long now = millis();
unsigned long wait = buzzerOn ? BEEP_ON_MS : BEEP_OFF_MS;
if (now - lastBeepChange >= wait) {
buzzerOn = !buzzerOn;
digitalWrite(PIN_BUZZER, buzzerOn ? HIGH : LOW);
lastBeepChange = now;
}
}
// Main status page (refreshes itself every 3 seconds)
void handleRoot() {
String color = isWet ? "#c62828" : "#2e7d32";
String state = isWet ? "WET - Rain detected" : "DRY";
String html;
html.reserve(1200);
html += F("<!DOCTYPE html><html><head><meta charset='utf-8'>"
"<meta name='viewport' content='width=device-width,initial-scale=1'>"
"<meta http-equiv='refresh' content='3'>"
"<title>Rain Detector</title>"
"<style>body{font-family:Arial;text-align:center;background:#f4f6f8;margin:0;padding:20px}"
".card{background:#fff;max-width:360px;margin:auto;padding:20px;border-radius:12px;"
"box-shadow:0 2px 8px rgba(0,0,0,.15)}"
".state{font-size:32px;font-weight:bold;color:#fff;padding:16px;border-radius:8px}"
"</style></head><body><div class='card'><h2>Wemos D1 Mini Rain Detector</h2>");
html += "<div class='state' style='background:" + color + "'>" + state + "</div>";
html += "<p>Analog reading (A0): <b>" + String(rainAnalog) + "</b> / 1023</p>";
html += "<p>Digital output (D5): <b>" + String(rainDigitalWet ? "WET" : "DRY") + "</b></p>";
if (isWet) {
html += "<p>Wet for " + String((millis() - wetSince) / 1000) + " s</p>";
}
html += "<p style='color:#777;font-size:12px'>Wet below " + String(WET_THRESHOLD) +
", dry above " + String(DRY_THRESHOLD) + ". Page refreshes every 3 s.</p>";
html += F("</div></body></html>");
server.send(200, "text/html", html);
}
// Machine-readable status for apps or Home Assistant
void handleJson() {
String json = "{\"state\":\"" + String(isWet ? "WET" : "DRY") +
"\",\"analog\":" + String(rainAnalog) +
",\"digital_wet\":" + String(rainDigitalWet ? "true" : "false") + "}";
server.send(200, "application/json", json);
}
void connectWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(F("Connecting to Wi-Fi"));
unsigned long start = millis();
while (WiFi.status() != WL_CONNECTED && millis() - start < 20000) {
delay(500);
Serial.print('.');
}
Serial.println();
if (WiFi.status() == WL_CONNECTED) {
Serial.print(F("Connected. Open http://"));
Serial.println(WiFi.localIP());
} else {
Serial.println(F("Wi-Fi not connected. The local alarm still works."));
}
}
void setup() {
Serial.begin(115200);
delay(100);
pinMode(PIN_RAIN_DO, INPUT);
pinMode(PIN_BUZZER, OUTPUT);
pinMode(PIN_LED, OUTPUT);
digitalWrite(PIN_BUZZER, LOW);
digitalWrite(PIN_LED, LOW);
connectWiFi();
server.on("/", handleRoot);
server.on("/json", handleJson);
server.begin();
readSensor();
}
void loop() {
server.handleClient();
if (millis() - lastRead >= READ_INTERVAL_MS) {
lastRead = millis();
readSensor();
}
updateAlarm();
// Try to reconnect if the router drops us
static unsigned long lastWifiCheck = 0;
if (millis() - lastWifiCheck > 30000) {
lastWifiCheck = millis();
if (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
}
}
}
How to Build It
- Plug the rain pad into the two input pins on the LM393 module. Either way round is fine.
- Connect the module to the Wemos: VCC to 3V3, GND to G, AO to A0 and DO to D5.
- Fit the active buzzer: + to D6, − to G.
- Fit the LED: D7 to the 330 Ω resistor, the resistor to the LED anode (long leg), and the cathode to G.
- Open the sketch, put in your Wi-Fi name and password, and upload it over USB.
- Open the Serial Monitor at 115200 baud. Note the IP address printed after Connected. Open http://.
- Mount the pad outdoors, tilted slightly so water runs off. Keep the LM393 module and the Wemos dry, under a roof or in a small box, and use longer wires only between the pad and the module.
Testing and Calibration
- With the pad dry, the Serial Monitor should show an A0 value close to 1024 and state=DRY. The LED and buzzer stay off.
- Put a few drops of water on the pad with your finger. A0 drops, the module DO LED lights, and the Wemos LED and buzzer turn on within half a second.
- Open
http://<IP address>/on a phone on the same Wi-Fi. The box should say WET – Rain detected in red, with the analog reading underneath. - Dry the pad with a tissue. After the reading climbs back above 700 the page returns to green DRY and the alarm stops.
- If the alarm trips too easily (for example from dew), turn the module pot to make DO less sensitive and lower
WET_THRESHOLDin the sketch. If it misses light drizzle, do the opposite.
Troubleshooting
| Problem | Fix |
|---|---|
| A0 always reads about 1024, even when wet | Check the AO wire to A0 and the pad wires to the module. Make sure the module VCC is really on 3V3. |
| Always WET, even when dry | DO may be stuck LOW: turn the sensitivity pot until the DO LED goes off with a dry pad. Dirty or corroded pads also read low — clean them. |
| Board will not boot or keeps resetting | Make sure nothing is wired to D3, D4 or D8. Use a good USB cable and charger. |
| Buzzer is very quiet or silent | It may be a passive buzzer (needs a tone signal) or a 5 V type. Use a 3.3 V active buzzer, or a module/transistor as described above. |
| No IP address in the Serial Monitor | Check the SSID and password, and that your router offers 2.4 GHz Wi-Fi. The ESP8266 cannot join 5 GHz networks. |
| Web page does not open | The phone must be on the same network. Type the IP exactly, with http:// and not https. |
Ideas to Extend This Project
- Power the rain module from a spare GPIO and switch it on only for each reading. That slows down corrosion of the pad a lot.
- Send a phone notification with a service such as ntfy, Telegram or Pushover when the state changes to WET.
- Add a DHT22 or BME280 on D1/D2 (I2C) and turn the page into a small weather station.
- Use deep sleep with a wake-up timer to run the detector from batteries.
FAQ
Can I power the rain module from 5 V? Not in this build. With 5 V on the module, its DO pin can swing to 5 V, which is more than an ESP8266 input should see. The module works well on 3.3 V.
Why does the wet reading go down instead of up? Water lowers the resistance between the tracks, which pulls the AO voltage down. So a smaller A0 number means more water.
Do I need both AO and DO? No. Either one is enough, but using both lets you set a hardware trip point with the pot and still see how wet the pad is on the web page.
Will this work with a NodeMCU board? Yes. The NodeMCU uses the same D5, D6, D7 and A0 labels, so the wiring and sketch are the same. Choose NodeMCU 1.0 (ESP-12E Module) as the board.
How long does the rain pad last outdoors? Months to a year with the module always powered, longer if you power it only while reading. Replacement pads are cheap.
Related Projects
- Wemos D1 Mini MQ-2 Gas Leak Detector
- ESP8266 NodeMCU 4-Relay Home Automation
- Automatic Plant Watering System with Arduino
- ESP32 DHT11 Weather Station with Web Server
Browse more ESP8266 Projects on Arduino Project Hub.
1 thought on “Wemos D1 Mini Rain Detector with Wi-Fi Alert”