Water damage is one of the most expensive and preventable disasters in Indian homes, offices, and factories. An IoT water leak detector with Telegram alerts built using ESP32 can save you from flooded basements, burst pipes under kitchen sinks, or leaking AC drain pipes — all for under ₹500 in components. In this complete project guide, we will build a real-time water leak detection system that sends instant Telegram notifications to your phone the moment water is detected anywhere in your premises.
This project is perfect for Indian homeowners living in apartments prone to pipeline issues, small business owners with server rooms, or anyone who wants peace of mind during the monsoon season. Let us get started.
How the IoT Water Leak Detector Works
The system is elegantly simple. A water/moisture sensor — typically a PCB with exposed copper traces — changes its electrical resistance when water bridges the gap between the traces. The ESP32 reads this change via an analog GPIO pin. When moisture crosses a threshold, the ESP32:
- Connects to your Wi-Fi network
- Sends an HTTPS POST request to the Telegram Bot API
- Your Telegram app receives a push notification within 1-2 seconds
- Optionally activates a buzzer or relay to cut off the water supply
The entire system can run on a 5V USB adapter or a battery pack, making it easy to deploy near washing machines, under kitchen sinks, behind water heaters (geysers), or at the base of water tanks.
Components Required
| Component | Quantity | Notes |
|---|---|---|
| ESP32 Development Board | 1 | Any variant works |
| Water/Moisture Sensor Module | 1-4 | One per zone |
| Buzzer (active, 5V) | 1 | Optional alarm |
| 5V Relay Module | 1 | For auto shutoff |
| USB 5V Adapter | 1 | For continuous power |
| Jumper Wires | Several | Male-to-female |
Ai Thinker NodeMCU-32S-ESP32 Development Board
The brain of this water leak detector — dual-core 240MHz with built-in Wi-Fi for fast Telegram notifications and multiple analog GPIO pins for multi-zone sensing.
Setting Up Telegram Bot for Alerts
Telegram is the ideal notification platform for Indian IoT projects — it is free, reliable, works on 2G/3G, and the Bot API is simple to use over HTTPS. Follow these steps:
Step 1: Create a Telegram Bot
- Open Telegram and search for @BotFather
- Send the command
/newbot - Follow the prompts to name your bot (e.g., “My Home Leak Alert”)
- BotFather will give you a Bot Token — save it, looks like:
123456789:ABCdefGHI...
Step 2: Get Your Chat ID
- Start a conversation with your new bot (send it any message)
- Open this URL in a browser:
https://api.telegram.org/bot{YOUR_TOKEN}/getUpdates - Find the
"id"field inside the"chat"object — this is your Chat ID
Step 3: Test the API
Test that your bot can send messages by visiting this URL:
https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={CHAT_ID}&text=Hello+from+ESP32!
If you see a message in Telegram, your bot is working correctly.
Circuit Diagram and Wiring
The wiring for this project is minimal:
| Component Pin | ESP32 Pin |
|---|---|
| Sensor VCC | 3.3V |
| Sensor GND | GND |
| Sensor AOUT (Analog) | GPIO 34 |
| Sensor DOUT (Digital) | GPIO 35 |
| Buzzer (+) | GPIO 26 |
| Buzzer (-) | GND |
Important for Indian conditions: Place the sensor probes (the exposed PCB pad) flat on the floor. Run waterproof wiring from the probe to the ESP32 control unit mounted at a higher, dry location. Use food-grade silicone sealant to protect any exposed PCB components near damp areas.
Complete Arduino Code
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const String BOT_TOKEN = "YOUR_BOT_TOKEN";
const String CHAT_ID = "YOUR_CHAT_ID";
#define SENSOR_ANALOG_PIN 34
#define SENSOR_DIGITAL_PIN 35
#define BUZZER_PIN 26
#define LEAK_THRESHOLD 1000 // Adjust based on your sensor
#define ALERT_COOLDOWN 60000 // 60 second cooldown between alerts
unsigned long lastAlertTime = 0;
bool leakDetected = false;
void setup() {
Serial.begin(115200);
pinMode(SENSOR_DIGITAL_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("nConnected! IP: " + WiFi.localIP().toString());
sendTelegramMessage("Water Leak Detector Online - Monitoring started");
}
void loop() {
int analogValue = analogRead(SENSOR_ANALOG_PIN);
int digitalValue = digitalRead(SENSOR_DIGITAL_PIN);
Serial.printf("Analog: %d, Digital: %dn", analogValue, digitalValue);
bool waterPresent = (analogValue > LEAK_THRESHOLD) || (digitalValue == LOW);
if (waterPresent && !leakDetected) {
leakDetected = true;
digitalWrite(BUZZER_PIN, HIGH);
String msg = "WATER LEAK DETECTED!nLocation: Kitchen SinknSensor Value: " + String(analogValue) + "nTime: " + String(millis()/1000) + "s uptime";
sendTelegramMessage(msg);
lastAlertTime = millis();
} else if (!waterPresent && leakDetected) {
leakDetected = false;
digitalWrite(BUZZER_PIN, LOW);
sendTelegramMessage("Water leak CLEARED. Area is now dry.");
} else if (waterPresent && (millis() - lastAlertTime > ALERT_COOLDOWN)) {
// Repeat alert if leak persists
sendTelegramMessage("REMINDER: Water leak still detected! Please check.");
lastAlertTime = millis();
}
delay(1000);
}
void sendTelegramMessage(String message) {
if (WiFi.status() != WL_CONNECTED) return;
WiFiClientSecure client;
client.setInsecure(); // Use proper cert in production
HTTPClient https;
String url = "https://api.telegram.org/bot" + BOT_TOKEN + "/sendMessage";
if (https.begin(client, url)) {
https.addHeader("Content-Type", "application/json");
String body = "{"chat_id":"" + CHAT_ID + "","text":"" + message + "","parse_mode":"HTML"}";
int code = https.POST(body);
Serial.println("Telegram response code: " + String(code));
https.end();
}
}
Enclosure and Deployment Tips for Indian Conditions
Indian homes present unique deployment challenges — humidity, monsoon moisture, power fluctuations, and sometimes rats chewing cables. Here are practical tips:
- Use IP65-rated junction boxes for the ESP32 unit if mounting in semi-exposed areas
- Power via PoE adapter or 5V phone charger — keep the device always on, do not rely on batteries alone
- Add a TVS diode across the power input to protect from voltage spikes common in Indian electrical grids
- Label your sensor probe cables clearly — in multi-zone setups, a sticker on each cable saves confusion during maintenance
- Monsoon preparation: Check all sensor pads before the monsoon season. Clean corroded probes with a pencil eraser or fine sandpaper
- Mount control unit high: In areas prone to flooding (ground-floor flats, basements), mount the ESP32 unit at least 50cm above floor level
2 x 18650 Lithium Battery Shield V8 for ESP32
Keep your water leak detector running even during power cuts with this dual 18650 battery shield — provides UPS-like backup power for continuous protection.
Advanced Features: Multiple Zones and Auto Shutoff
Once your basic system is working, here are upgrades to consider:
Multi-Zone Monitoring
ESP32 has up to 18 ADC channels. Connect multiple sensor pads to different GPIO pins and detect leaks in the bathroom, kitchen, balcony, and utility room simultaneously. Modify the code to tag each alert with the zone name (e.g., “LEAK at: Bathroom — near Western Commode”).
Automated Water Shutoff
Add a solenoid valve controlled via a relay to your main water line. When a leak is detected, the ESP32 triggers the relay to close the valve, stopping water flow before damage spreads. Include a manual override button so you can reopen the valve after fixing the leak.
Telegram Inline Buttons
Use Telegram’s InlineKeyboardMarkup in your API call to add buttons to the alert message like “Silence Alarm” or “Reopen Valve” — the ESP32 can poll the Telegram Bot API for updates and respond to these button presses.
30Pin ESP32 Expansion Board with Type-C USB
This expansion board makes multi-zone wiring easy — all 30 pins are broken out with convenient screw terminals, ideal for connecting multiple sensor probes across your home.
Frequently Asked Questions
Q1: Will the water leak detector work during Wi-Fi outages?
The local buzzer and LED will still activate during Wi-Fi outages. The Telegram alert will be queued and sent once connectivity is restored (if you implement a retry mechanism in the code). For critical installations, consider adding a GSM module (SIM800L) as a fallback alert channel.
Q2: How long do the water sensor probes last before corrosion?
Standard resistive sensors corrode within 1-3 months if frequently exposed to water. To extend lifespan: only power the sensor during measurement (use a GPIO pin as VCC, pull it HIGH only when sampling). Alternatively, use capacitive soil/water sensors which have no exposed metal contacts and last years.
Q3: Can I monitor multiple locations in my house?
Yes. Use multiple sensors connected to different GPIO pins on a single ESP32, or deploy multiple ESP32 units and have them all post to the same Telegram group chat. The second approach is more reliable for large homes or offices.
Q4: Can I use this with ESP8266 instead of ESP32?
Yes. The ESP8266 (D1 Mini, NodeMCU) also supports the Telegram Bot API via HTTPS. Use the WiFiClientSecure and ESP8266HTTPClient libraries. However, ESP32 is recommended for its more stable TLS implementation and additional GPIO pins for multi-zone monitoring.
Protect Your Home Today
Get the ESP32 boards, sensors, and accessories needed to build your water leak detector from Zbotic — fast delivery across India with genuine components.
Add comment