Embedded SystemsBeginnerPRJ-172

Smart Water Leakage Detection & Auto Shutoff Using ESP32

Detects a water leak and shuts the supply valve automatically.

Built and tested by Anju.A · Industrial Robotics Institute

ESP32

Arduino IDE, Blynk (optional)

LevelBeginner
Build time1–2 hours
BoardESP32
Parts8 components

What is the Smart Water Leakage Detection & Auto Shutoff?

A leak protection system for homes and offices. A water sensor on the floor or near a pipe detects leaking water; the ESP32 immediately closes a 12V solenoid valve through a relay to cut the supply, and sounds a buzzer, preventing damage and water waste.

How it works

  1. The water leakage sensor detects water (output HIGH).
  2. The ESP32 switches the relay off, closing the solenoid valve and cutting the supply.
  3. The buzzer sounds to alert people nearby.
  4. When the area is dry again, the valve reopens and the buzzer stops.

Parts list

ComponentQty
ESP32 Dev Board1
Water Leakage Sensor (YL-69 / probe)1
12V Solenoid Water Valve1
Relay Module1
Buzzer1
Jumper Wires / BreadboardAs needed
12V Power Supply (valve)1
5V Power Supply (ESP32)1

Software

  • Arduino IDE
  • Blynk (optional)

Wiring and connections

FromConnect to
Leak sensor VCC3.3V
Leak sensor GNDGND
Leak sensor DOGPIO 34
Relay VCC5V
Relay GNDGND
Relay INGPIO 26
Solenoid valve12V supply through relay COM / NO
Buzzer +GPIO 25
Buzzer −GND

How to build the Smart Water Leakage Detection & Auto Shutoff

  1. Place the leak sensor on the floor under the tank or pipe joint.
  2. Connect the sensor DO to GPIO 34, the relay to GPIO 26 and the buzzer to GPIO 25.
  3. Wire the solenoid valve to its 12V supply through the relay’s COM and NO terminals.
  4. Fit the valve in the water line (get a plumber for mains pipes).
  5. Upload the code and test by wetting the sensor.

Smart Water Leakage Detection & Auto Shutoff code

Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the ESP32.

#define sensorPin 34
#define relayPin  26
#define buzzerPin 25

void setup() {
  pinMode(sensorPin, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  int sensorValue = digitalRead(sensorPin);

  if (sensorValue == HIGH) {         // water detected
    Serial.println("Leakage Detected!");
    digitalWrite(relayPin, LOW);     // valve OFF (supply cut)
    digitalWrite(buzzerPin, HIGH);   // alert ON
    delay(2000);
  } else {
    digitalWrite(relayPin, HIGH);    // valve ON
    digitalWrite(buzzerPin, LOW);    // alert OFF
  }

  delay(500);
}

Real-world uses

  • Homes and apartments
  • Offices and server rooms
  • Water tanks and pump rooms
  • Water conservation projects

Frequently asked questions

What is a Smart Water Leakage Detection & Auto Shutoff?

A leak protection system for homes and offices. A water sensor on the floor or near a pipe detects leaking water; the ESP32 immediately closes a 12V solenoid valve through a relay to cut the supply, and sounds a buzzer, preventing damage and water waste.

What components are needed for the Smart Water Leakage Detection & Auto Shutoff?

You need: ESP32 Dev Board (1), Water Leakage Sensor (YL-69 / probe) (1), 12V Solenoid Water Valve (1), Relay Module (1), Buzzer (1), Jumper Wires / Breadboard, 12V Power Supply (valve) (1), 5V Power Supply (ESP32) (1). Software: Arduino IDE, Blynk (optional).

Is the Smart Water Leakage Detection & Auto Shutoff project good for beginners?

Yes. It is rated beginner and takes about 1–2 hours to build, using the ESP32. The guide on this page explains every connection and step.

Where can I get the code for the Smart Water Leakage Detection & Auto Shutoff?

The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.

Can I buy a kit for the Smart Water Leakage Detection & Auto Shutoff?

Yes. IRI sells a kit with the parts for this project (PRJ-172). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.

Industrial Robotics Institute
Logo