Level: Beginner Board: ESP32 DevKit V1 (WROOM-32) Water & garden
⚠ Safety Keep the electronics above floor level in a dry box; only the probe touches water.
What you need Buy the parts kit · Estimated total: $5.50
ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Water leak sensor module (comparator) × 1
$1.00
Active buzzer module 5V × 1
$0.50
Some links are affiliate links: we may earn a commission at no extra cost to you.
Code water-leak-sensor.ino Copy Download .ino
#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);
}Flash a ready firmware from the browser Paste your error into the AI Error Doctor
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. ← ← All projects
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.
Watches the pit for water, tells you when the mains is gone and the backup is running, and rings an alarm before the pit overflows.
A pressure sensor on the inlet tells you when the water is cut off or comes back, with a message and the time.
⚠ Caution Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.
A battery logger with display and alerts for fridges, freezers and cold storage, keeps recording through blackouts.
Comments
No comments yet. Share your experience or ask a question.