Battery water-leak sensor with Telegram alert

Sleeps in deep sleep, wakes on water contact and sends a Telegram message. Also sends a heartbeat every 12 hours.

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
Buy at AliExpress Buy at Amazon.com
Water leak sensor module (comparator) × 1
$1.00
Buy at AliExpress Buy at Amazon.com
Active buzzer module 5V × 1
$0.50
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

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.

Wiring

ModuleModule pinESP32 pinNote
Leak module VCC / GND3V3 / GND
Leak module DOdigitalGPIO27LOW = water (check your module)
Buzzer +signalGPIO25

Code

water-leak-sensor.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.

Sump or well pump backup monitor

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.

  • Board ESP32-C3 SuperMini
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit

Water outage notifier

A pressure sensor on the inlet tells you when the water is cut off or comes back, with a message and the time.

  • Board ESP32-C3 SuperMini
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit
⚠ Caution

Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.

Cold-chain temperature logger

A battery logger with display and alerts for fridges, freezers and cold storage, keeps recording through blackouts.

  • Board ESP32-C3 SuperMini
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.