Hidden Pipe Leak Locator with ESP32

Hidden Pipe Leak Locator with ESP32 – Kids Robotics Project | MakeMindz
ESP32Ages 9–14About 90 minutesBeginner+

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!

All pipes are dry. Press a button to spring a leak!

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.

Safety first: Keep the ESP32, relay and breadboard in a dry box above the tray. Only the sensors go near water. Ask an adult before plugging in the 12 V adapter.

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.

PartConnects to ESP32Power / notes
Sensor A, B, C, D (signal)GPIO 34, 35, 32, 33VCC to 3.3V, GND to GND
LED A, B, C, D (long leg)GPIO 25, 26, 27, 14220 Ω resistor, short leg to GND
Buzzer (+)GPIO 23Buzzer (–) to GND
Relay IN1, IN2, IN3, IN4GPIO 16, 17, 18, 19Relay VCC to 5V (VIN), GND to GND
Valves A–DRelay outputs 1–412 V adapter + to relay COM, valve wire to NO
Reset buttonGPIO 4Other leg to GND
Remember: ESP32 pins only handle 3.3 V. Power the water sensors from 3.3V, not 5V, so the signal never goes too high for the ESP32.

Step-by-step instructions

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Upload the code

    Install the ESP32 board in Arduino IDE, choose ESP32 Dev Module, paste the code below and click Upload.
  7. Test and calibrate

    Open Serial Monitor at 115200 baud. Note the dry numbers, then touch a wet finger to a sensor. Set WET_LIMIT halfway 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.

Made with 💜 by MakeMindz – robotics and maker projects for kids.

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
★★★★★ Young inventors love it!
🖨️
3D Print
All parts
⚡
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 ₹300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
★★★★★ Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 ₹200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course