The simplest leak sensor are two bare electrodes: water closes the gap. With constant DC the electrodes electrolyse and corrode within weeks. Power the probe from a GPIO only for a few milliseconds when measuring, or use stainless steel or gold-plated contacts.
Where to put it and how to test it
Water finds the lowest point, so put the probe on the floor under the washing machine, the dishwasher, the water heater and below the sink, with the contacts a millimetre above the floor. The ESP32-C3 on a battery sleeps most of the time and wakes on a GPIO level, so the alarm does not depend on the network.
Add a local buzzer and a Telegram message. Either alone is weaker.
Test the sensor with a spoon of water once a month, and put the reminder in your calendar.
An obvious upgrade is a motorised ball valve that closes the water. It is powerful and dangerous: it needs a fail-safe design and a manual override.
Components
ESP32-C3 SuperMini
Water leak sensor module (comparator) × 2
Active buzzer module 5V
Dupont jumper wires (M-F, M-M)
Wiring
Module
Module pin
ESP32 pin
Note
Leak module VCC / GND
3V3 / GND
Leak module DO
digital
GPIO27
LOW = water (check your module)
Buzzer +
signal
GPIO25
Code
#include <WiFi.h>
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";
bool connectWiFi(uint32_t timeoutMs = 20000) {
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
uint32_t t0 = millis();
while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
delay(250);
Serial.print(".");
}
Serial.println();
if (WiFi.status() == WL_CONNECTED) {
Serial.print("IP: ");
Serial.println(WiFi.localIP());
return true;
}
return false;
}
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
const char* TG_TOKEN = "123456:ABC-YOUR-BOT-TOKEN"; // from @BotFather
const char* TG_CHAT = "YOUR_CHAT_ID";
// Keep the text free of double quotes and line breaks (it is inserted into JSON).
bool telegramSend(const String& text) {
if (WiFi.status() != WL_CONNECTED) return false;
WiFiClientSecure client;
client.setInsecure(); // simple; pin the certificate for production
HTTPClient http;
String url = String("https://api.telegram.org/bot") + TG_TOKEN + "/sendMessage";
if (!http.begin(client, url)) return false;
http.addHeader("Content-Type", "application/json");
String body = String("{"chat_id":"") + TG_CHAT + "","text":"" + text + ""}";
int code = http.POST(body);
http.end();
return code == 200;
}
const int PIN_LEAK = 27, PIN_BUZ = 25;
bool alarmSent = false;
void setup() {
pinMode(PIN_LEAK, INPUT_PULLUP); pinMode(PIN_BUZ, OUTPUT);
Serial.begin(115200);
connectWiFi();
}
void loop() {
bool wet = digitalRead(PIN_LEAK) == LOW;
digitalWrite(PIN_BUZ, wet ? HIGH : LOW);
if (wet && !alarmSent) { alarmSent = telegramSend("Water leak detected!"); }
if (!wet) alarmSent = false;
if (WiFi.status() != WL_CONNECTED) connectWiFi(5000);
delay(500);
}
Build tips
Place the probe flat on the floor near the washing machine or boiler.
Use a good 2xAAA or 18650 cell with a low-quiescent regulator for months of runtime.
Other countries: order these parts on AliExpress with the links below.
Some links are affiliate links: we may earn a commission at no extra cost to you.
Related ideas
⛔ High risk
Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.
Comments
No comments yet. Share your experience or ask a question.