A smart water leak detector using ESP8266 can save Indian homeowners from costly water damage — especially relevant during monsoon season, with overhead water tanks, or in apartments with shared plumbing. When water is detected, the ESP8266 instantly sends Telegram/WhatsApp alerts and can automatically shut off a valve. This guide covers building a comprehensive water leak detection system for Indian homes using readily available components.
Table of Contents
- Why Water Leak Detection in India
- Water Sensor Options in India
- Circuit Design
- ESP8266 Code with Notifications
- Telegram Alert System
- Automatic Valve Shutoff
- Sensor Placement in Indian Homes
- Frequently Asked Questions
Why Water Leak Detection in India
Water leaks are a significant concern in Indian homes and apartments for several reasons:
- Overhead tanks: Many Indian buildings have rooftop tanks — overflow can cause ceiling damage in flats below
- Monsoon season: June–September brings heavy rains; roof leaks, window seepage, and basement flooding are common
- Old plumbing: Much of India’s residential plumbing infrastructure is aging — pipe bursts and joint failures are frequent
- Water pressure issues: High municipal pressure periods can stress pipes and fittings
- Kitchen and bathroom leaks: Under-sink pipe connections, washing machine hoses
- AC condensate: Air conditioner drip trays overflowing in summer
Water Sensor Options in India
Several water detection sensor options are available in India:
- Water/rain sensor module: ₹30–₆0. Simple resistive sensor — trace PCB with copper tracks. Detects presence of water by reduced resistance. Available everywhere in India.
- Capacitive water level sensor: ₹80–₁50. More reliable for continuous submersion. Won’t corrode like resistive sensors.
- eTape/water level sensor: ₹200–₄00. Continuous level measurement (not just presence).
- Float switch: ₹30–₈0. Mechanical switch that triggers on water level rise. Zero electronics required — simplest approach.
Circuit Design
/* Water Leak Detector Circuit */
// Components:
// - ESP8266 (D1 Mini or NodeMCU)
// - Water/rain sensor module
// - 5V buzzer (optional)
// - Green LED (normal) + Red LED (alert)
// - 12V solenoid valve + relay (for automatic shutoff, optional)
// Water sensor to ESP8266:
// Sensor module VCC → 3.3V (NOT 5V for digital pin reading)
// Sensor module GND → GND
// Sensor module DO → ESP8266 D5 (GPIO14) - Digital Output
// Sensor module AO → ESP8266 A0 - Analog (optional for level measurement)
// Indicator LEDs:
// Green LED → D6 (GPIO12) via 220Ω
// Red LED → D7 (GPIO13) via 220Ω
// Buzzer:
// Buzzer + → D8 (GPIO15) via 100Ω
// Buzzer - → GND
// Water sensor calibration:
// Dry sensor: DO = HIGH (no leak)
// Wet sensor: DO = LOW (leak detected!)
// Most sensor modules are active-LOW when water detected
ESP8266 Code with Notifications
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "YourWiFi";
const char* password = "YourPassword";
#define SENSOR_PIN D5 // GPIO14 - Water sensor digital output
#define RED_LED D7 // GPIO13
#define GREEN_LED D6 // GPIO12
#define BUZZER_PIN D8 // GPIO15
#define VALVE_RELAY D1 // GPIO5 (for solenoid valve)
// Alert thresholds to prevent spam
unsigned long lastAlertTime = 0;
const unsigned long ALERT_COOLDOWN = 300000; // 5 minutes between alerts
bool leakDetected = false;
bool previousState = false;
void setup() {
Serial.begin(115200);
pinMode(SENSOR_PIN, INPUT);
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(VALVE_RELAY, OUTPUT);
// Start with valve open, green LED on
digitalWrite(VALVE_RELAY, LOW); // Valve open
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("
Connected! IP: " + WiFi.localIP().toString());
Serial.println("Water leak detector armed and ready");
}
void loop() {
// Read water sensor (active LOW = water detected)
bool waterDetected = (digitalRead(SENSOR_PIN) == LOW);
// Leak started
if (waterDetected && !previousState) {
leakDetected = true;
Serial.println("WATER LEAK DETECTED!");
// Visual and audio alert
digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, LOW);
// Beep buzzer urgently
for (int i = 0; i ALERT_COOLDOWN)) {
sendTelegramAlert("⚠️ Water leak still active! Please check immediately.");
lastAlertTime = millis();
}
previousState = waterDetected;
delay(500); // Check every 500ms
}
Telegram Alert System
WiFiClientSecure client;
const String BOT_TOKEN = "your-bot-token";
const String CHAT_ID = "your-chat-id";
void sendTelegramAlert(String message) {
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi not connected - alert not sent");
return;
}
client.setInsecure(); // Skip cert verification for simplicity
if (client.connect("api.telegram.org", 443)) {
String url = "/bot" + BOT_TOKEN + "/sendMessage?chat_id=" +
CHAT_ID + "&text=" + urlencode(message) +
"&parse_mode=HTML";
client.print("GET " + url + " HTTP/1.1
");
client.print("Host: api.telegram.org
");
client.print("Connection: close
");
delay(1000);
while (client.available()) {
String line = client.readStringUntil('
');
if (line.indexOf(""ok":true") > 0) {
Serial.println("Telegram alert sent successfully");
}
}
client.stop();
}
}
String urlencode(String str) {
String encodedString = "";
char c;
for (int i = 0; i < str.length(); i++) {
c = str.charAt(i);
if (c == ' ') encodedString += '+';
else if (isalnum(c)) encodedString += c;
else encodedString += '%' + String(c, HEX);
}
return encodedString;
}
Automatic Valve Shutoff
For automatic water shutoff, add a 12V or 24V solenoid valve:
- 12V Solenoid Valve (1/2 inch): ₹300–₆00 on Amazon India. Install on main water supply line.
- NC (Normally Closed) solenoid valve: Stays CLOSED when no power — fails safe during power cuts
- NO (Normally Open) solenoid valve: Stays OPEN when no power — requires power to close
For Indian homes: Use NC type for main supply line shutoff — if power goes out during a leak, valve stays closed (safe). Use NO type for water distribution lines where you want normal operation during power cuts.
Sensor Placement in Indian Homes
- Under kitchen sink: Under the pipe connections where Indian homes commonly leak
- Under washing machine: Behind or beside the machine on the floor
- Bathroom near AC drip pipe: Where split AC condensate drains
- Near water heater/geyser: Geysers leak from pressure relief valves and connections
- Terrace/balcony drain: Detects blockage before water enters the home
- Basement (if applicable): Common leak point in older Indian buildings during monsoon
Frequently Asked Questions
How long do water sensor probes last in Indian conditions?
Resistive water sensor modules (copper trace PCBs) can corrode in 6–12 months in humid Indian conditions. Use stainless steel probes or capacitive sensors for longer life. Coating the PCB with conformal spray (except the sensing area) extends life significantly.
Can this system detect slow pipe leaks inside walls?
Surface water sensors detect water after it has reached the floor — they cannot detect leaks inside walls. For wall leaks, professional acoustic leak detection equipment is needed. For DIY monitoring, place sensors at every possible exit point of wall cavities (floor level at skirting).
What solenoid valve size is needed for Indian residential water lines?
Indian residential water supply pipes are typically 1/2 inch (15mm) or 3/4 inch (20mm) near fixtures. Use a 1/2 inch valve for single fixture monitoring and a 3/4 inch to 1 inch valve for main supply shutoff at the metre.
Can ESP8266 run on battery for water leak sensing?
ESP8266 active WiFi draws 80–200mA — too much for battery. For battery-powered sensors, use deep sleep: check sensor every 30 seconds, transmit alert only when leak detected. With 3000mAh LiPo and 30-second check interval, battery life is several months. Add a capacitor (470μF) to handle WiFi startup current spikes.
Is there an Indian standard for water leak detectors?
No specific IS standard for DIY home water leak detectors. For commercial installations (hotels, hospitals), IS: 2189 for fire detection applies to some water detection equipment. DIY systems are for personal use — ensure the electrical parts are properly isolated from water using appropriate IP ratings.
Add comment