Hidden Pipe Leak Locator with ESP32
Water leaks hide inside walls and under floors, so plumbers need to know which part of a pipe is leaking. In this ESP32 robotics project you build a model pipeline with four sections. When one section leaks, the sensor there gets wet, an LED lights up, the buzzer beeps and a valve shuts the water off. Try the pretend pipeline below first!
How does it work?
Sense
A water sensor under each pipe section has metal lines. Water joins the lines together and the sensor's signal goes up.
Think
The ESP32 reads all four sensors. The one with a high number is the leaky section.
Warn
That section's LED turns on and the buzzer beeps once for A, twice for B, and so on.
Stop
The ESP32 switches a relay so the valve for that section closes and the leak stops.
What you need
ESP32 DevKit ×1
The brain of the project.
Water sensors ×4
Analog water or rain sensor modules.
LEDs ×4
Red is best, plus four 220 Ω resistors.
Active buzzer ×1
It beeps when powered.
Mini valves ×4
12 V solenoid valves for the model pipes.
4-channel relay module ×1
Lets the ESP32 switch the valves safely.
12 V adapter ×1
Powers the valves. Adult help needed.
Extras
Breadboard, jumper wires, push button, clear tubing, tray, tape.
Circuit diagram
Each pipe section (A, B, C, D) gets its own sensor, LED and valve. All four sensors use ESP32 pins that work for analog reading even when Wi-Fi is on.
| Part | Connects to ESP32 | Power / notes |
|---|---|---|
| Sensor A, B, C, D (signal) | GPIO 34, 35, 32, 33 | VCC to 3.3V, GND to GND |
| LED A, B, C, D (long leg) | GPIO 25, 26, 27, 14 | 220 Ω resistor, short leg to GND |
| Buzzer (+) | GPIO 23 | Buzzer (–) to GND |
| Relay IN1, IN2, IN3, IN4 | GPIO 16, 17, 18, 19 | Relay VCC to 5V (VIN), GND to GND |
| Valves A–D | Relay outputs 1–4 | 12 V adapter + to relay COM, valve wire to NO |
| Reset button | GPIO 4 | Other leg to GND |
Step-by-step instructions
Build the model pipeline
Join four pieces of clear tubing into one long pipe and label them A, B, C and D. Place the pipeline on a plastic tray so spills stay tidy.Fit the water sensors
Tape one water sensor under each pipe section, sensor face up, so a drip lands on it. Never let the sensor's wire end get wet.Wire the sensors
Connect each sensor's VCC to 3.3V, GND to GND and signal to GPIO 34, 35, 32 and 33 in order A to D.Add LEDs and the buzzer
Put the four LEDs along the front of your model. Connect each long leg through a 220 Ω resistor to GPIO 25, 26, 27 and 14. Connect the buzzer to GPIO 23.Connect the valves through the relay
Wire relay inputs to GPIO 16–19. Connect the 12 V adapter plus to each relay COM and each valve to the NO terminal. Join the adapter minus to the valves' other wires. Ask an adult to check this step.Upload the code
Install the ESP32 board in Arduino IDE, choose ESP32 Dev Module, paste the code below and click Upload.Test and calibrate
Open Serial Monitor at 115200 baud. Note the dry numbers, then touch a wet finger to a sensor. SetWET_LIMIThalfway between dry and wet. Drip water on sensor B and watch LED B, the buzzer and valve B react!
ESP32 code
// Hidden Pipe Leak Locator - MakeMindz
const int NUM = 4;
const int sensorPins[NUM] = {34, 35, 32, 33};
const int ledPins[NUM] = {25, 26, 27, 14};
const int valvePins[NUM] = {16, 17, 18, 19};
const int buzzerPin = 23;
const int resetPin = 4;
const int WET_LIMIT = 1500; // calibrate: halfway between dry and wet
const int NEED_WET = 3; // wet readings in a row = real leak
const int RELAY_ON = LOW; // most relay modules switch on with LOW
const int RELAY_OFF = HIGH;
int wetCount[NUM];
bool leaking[NUM];
int readAvg(int pin) {
long total = 0;
for (int i = 0; i < 5; i++) { total += analogRead(pin); delay(2); }
return total / 5;
}
void beepTimes(int n) {
for (int i = 0; i < n; i++) {
digitalWrite(buzzerPin, HIGH); delay(150);
digitalWrite(buzzerPin, LOW); delay(150);
}
}
void setup() {
Serial.begin(115200);
pinMode(buzzerPin, OUTPUT);
pinMode(resetPin, INPUT_PULLUP);
for (int i = 0; i < NUM; i++) {
pinMode(ledPins[i], OUTPUT);
pinMode(valvePins[i], OUTPUT);
digitalWrite(valvePins[i], RELAY_ON); // valve open = water flows
}
Serial.println("Leak locator ready!");
}
void loop() {
for (int i = 0; i < NUM; i++) {
int value = readAvg(sensorPins[i]);
wetCount[i] = (value > WET_LIMIT) ? wetCount[i] + 1 : 0;
if (wetCount[i] >= NEED_WET && !leaking[i]) {
leaking[i] = true;
Serial.print("LEAK in section ");
Serial.println((char)('A' + i));
}
digitalWrite(ledPins[i], leaking[i]);
digitalWrite(valvePins[i], leaking[i] ? RELAY_OFF : RELAY_ON);
}
for (int i = 0; i < NUM; i++) {
if (leaking[i]) { beepTimes(i + 1); delay(400); } // A=1 beep, B=2 ...
}
if (digitalRead(resetPin) == LOW) { // press button after fixing the leak
for (int i = 0; i < NUM; i++) { leaking[i] = false; wetCount[i] = 0; }
Serial.println("Reset - all clear");
}
delay(200);
}
Fix it: troubleshooting
🙈 LED never turns on
Check the LED's long leg faces the resistor and GPIO pin.
🔊 Buzzer beeps all the time
Your sensor is reading too high when dry. Raise WET_LIMIT or dry the sensor.
🔁 Valve works backwards
Swap RELAY_ON and RELAY_OFF, or move the valve wire from NO to NC.
📉 Numbers jump around
Use short wires and add a 0.1 µF capacitor between signal and GND.
Upgrade ideas
📱 Phone alerts
Use ESP32 Wi-Fi to send a message to your phone.
📺 OLED screen
Show the leaking section's name in big letters.
🌊 Flow sensor
Compare water flowing in and out to catch tiny leaks.
☁️ Dashboard
Log leak times to a web page.
Frequently asked questions
How does the leak locator know which pipe is leaking?
Every pipe section has its own sensor on its own ESP32 pin. The sensor that gets wet points to the leaking section.
Can I use an Arduino Uno instead of an ESP32?
Yes, but pin numbers change and sensors can use 5 V. The ESP32 is a bonus because Wi-Fi upgrades are easy.
Is this project safe for kids?
Yes, with low-voltage power, a dry electronics box and an adult helping with the 12 V valve supply.
What will I learn?
Analog sensors, thresholds, LEDs, relays, arrays, loops and how real smart-home leak detectors work.

Comments
Post a Comment