Build Project

Home Automation

ESP32 Water Leak Detector

A low-voltage water leak alarm that detects moisture on a sensor strip, sounds a buzzer, and can later send alerts over Wi-Fi. Includes wiring, code, troub

BeginnerAges 12+50-80 minUnder 20 USDParent Safe
Project Mission

Build a Water Leak Detector

The Story

ESP32 Water Leak Detector solves a real beginner problem: turning an ESP32 reading into a useful physical or networked result. Build this to learn practical threshold sensing, corrosion limits, and how a small ESP32 circuit can prevent real damage.

The tutorial focuses on the engineering path: prove the input, understand the circuit, write readable code, then test the output under real conditions.

Explain Like I'm 12

The water sensor is like two metal rails on the floor. Dry rails are mostly disconnected. Water bridges them, current can pass through the module, and the ESP32 sees the change.

Safety Standards

  • Unplug USB before changing jumper wires. Recheck 3.3 V, 5 V, and GND before reconnecting power.
  • Do not power motors, pumps, LED strips, or servos from the ESP32 3.3 V pin. Use a suitable external supply and common ground.
  • Breadboards are for low-current prototypes. Move high-current or unattended builds to proper terminals, enclosure, strain relief, and fusing.
  • Motors and servos can reset the ESP32 when they draw surge current. Use a separate motor supply, driver module, and flyback protection where needed.

What You Will Build

A low-voltage water leak alarm that detects moisture on a sensor strip, sounds a buzzer, and can later send alerts over Wi-Fi.

Learning Objectives

  • Detect water using analog and digital sensor outputs.
  • Understand why resistive water probes corrode over time.
  • Create a safe local buzzer/LED alarm.
  • Choose sensor placement for real leaks.
  • Prepare the project for future Wi-Fi alerts.

Components List

  • 1× ESP32 DevKit V1Required for this build
  • 1× Resistive water sensor stripParallel copper trace strip; inexpensive module
  • 1× Active buzzer 5 VRequired for this build
  • 1× Red LED and 220 ohm resistorLeak indicator
  • 1× Green LED and 220 ohm resistorNormal status indicator
  • 1× Breadboard and jumper wiresRequired for this build
  • USB data cableProgramming and bench power

Bill of Materials

PartQtyEstimated CostNotes
1× ESP32 DevKit V11VariesRequired for this build
1× Resistive water sensor strip1VariesParallel copper trace strip; inexpensive module
1× Active buzzer 5 V1VariesRequired for this build
1× Red LED and 220 ohm resistor1VariesLeak indicator
1× Green LED and 220 ohm resistor1VariesNormal status indicator
1× Breadboard and jumper wires1 setVariesRequired for this build

Wiring

Wire the input hardware first, confirm readings in Serial Monitor, then connect the output hardware. The water strip exposes conductive traces.

ESP32 Water Leak Detector wiring diagram
  1. 1

    Unplug USB before changing wires.

  2. 2

    Connect Water sensor AOUT to GPIO 34 (Analog signal; higher voltage = wetter).

  3. 3

    Connect Water sensor DOUT to GPIO 35 (Digital threshold from onboard comparator).

  4. 4

    Connect Water sensor VCC to 3.3 V (Power sensor only when reading to reduce electrolytic corrosion).

  5. 5

    Connect Water sensor GND to GND.

  6. 6

    Connect Buzzer + to GPIO 25.

  7. 7

    Connect Red LED anode to GPIO 26.

  8. 8

    Connect Green LED anode to GPIO 27.

  9. 9

    Reconnect USB, upload the sketch, and open Serial Monitor at 115200 baud unless the code says otherwise.

GPIO Mapping

SignalESP32 PinDirectionNotes
Water sensor AOUTGPIO 34InputAnalog signal; higher voltage = wetter
Water sensor DOUTGPIO 35InputDigital threshold from onboard comparator
Water sensor VCC3.3 VPowerPower sensor only when reading to reduce electrolytic corrosion
Water sensor GNDGNDGroundMatch this wire to the code constant.
Buzzer +GPIO 25OutputMatch this wire to the code constant.
Red LED anodeGPIO 26OutputMatch this wire to the code constant.
Green LED anodeGPIO 27OutputMatch this wire to the code constant.

Circuit Explanation

The water strip exposes conductive traces. When water touches the traces, resistance changes and the module output changes. The ESP32 can read the analog output for wetness level or digital output for simple leak/no-leak detection. LEDs and buzzer provide immediate local feedback.

Engineering Explanation

Water detection is simple electrically but tricky in real installations. Minerals in water, corrosion, condensation, sensor placement, and cable length affect reliability. A good detector powers the sensor only while reading, tests both wet and dry states, and places the probe where water appears first.

Libraries

  • Arduino ESP32 coreInstall ESP32 board support in Arduino IDE.

Code

Copy into Arduino IDE. Install any libraries noted in the component guides first.

esp32-water-leak-detector.ino
// ESP32 Water Leak Detector - Beginner
// Resistive moisture sensor; buzzer + LED alert

const int SENSOR_AOUT = 34;
const int SENSOR_DOUT = 35;
const int BUZZER  = 25;
const int LED_RED = 26;
const int LED_GRN = 27;

const int WET_THRESHOLD = 2000; // tune from Serial output; 0-4095

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  pinMode(SENSOR_DOUT, INPUT);
  pinMode(BUZZER,  OUTPUT);
  pinMode(LED_RED, OUTPUT);
  pinMode(LED_GRN, OUTPUT);
}

void loop() {
  int raw = analogRead(SENSOR_AOUT);
  bool wet = (raw > WET_THRESHOLD) || (digitalRead(SENSOR_DOUT) == HIGH);

  Serial.printf("Sensor: %d  Status: %sn", raw, wet ? "WET!" : "dry");

  if (wet) {
    digitalWrite(LED_RED, HIGH);
    digitalWrite(LED_GRN, LOW);
    digitalWrite(BUZZER,  HIGH);
  } else {
    digitalWrite(LED_RED, LOW);
    digitalWrite(LED_GRN, HIGH);
    digitalWrite(BUZZER,  LOW);
  }
  delay(1000);
}

Code Explanation

The sketch starts Serial Monitor, defines readable pin constants, configures input and output pins in setup(), then repeats the measurement and decision logic in loop(). The loop prints the live reading first, compares it with a threshold, then changes the output. Printing before controlling the output makes debugging much easier because you can see what the ESP32 believes is happening.

Expected Output

Serial Monitor should print live readings or status messages. The output should change only when the tested condition for esp32 water leak detector is reached.

Build Photos

  • Breadboard overviewShow ESP32, module, output device, and power rails.
  • Close-up wiringShow signal pins clearly enough for learners to compare.
  • Working outputShow Serial Monitor, LEDs, display, or dashboard after the condition changes.

Troubleshooting

  • Alarm always stays on Dry the sensor, check for residue between traces, and print raw readings before threshold logic.
  • Alarm never triggers Touch the traces with a damp cloth and verify VCC, GND, and signal wiring.
  • False alarms happen overnight Move the sensor away from condensation sources or raise the threshold after logging dry readings.
  • Buzzer is weak Use an active buzzer module and check whether it needs 5 V or a transistor driver.

Common Mistakes

  • Leaving a resistive water sensor powered continuously for months.
  • Placing the sensor where water reaches it too late.
  • Using the buzzer before proving the sensor reading works.
  • Ignoring corrosion after repeated wet tests.
  • Forgetting to dry the sensor completely before retesting.

Testing Checklist

  • Upload a simple Blink sketch first to confirm the board and USB cable work.
  • Wire only power and ground, then confirm the board still boots.
  • Connect the input signal and print raw readings before using thresholds.
  • Trigger the real-world condition slowly and watch Serial Monitor.
  • Connect the output only after the input reading is believable.
  • Power-cycle the project and confirm it starts in a safe state.

Engineering Tips

  • Power the sensor only during measurement to reduce electrolysis.
  • Keep the ESP32 board away from the wet area.
  • Use a drip loop in cables so water cannot run toward electronics.
  • Test with a damp cloth, not a cup of water near the board.
  • Use a plastic enclosure for permanent monitoring.

Performance Tips

  • Sleep between checks for battery operation.
  • Use digital output for simple alarms and analog output for wetness trend.
  • Require two wet readings before sounding the alarm.
  • Send network alerts only when the state changes.

Upgrade Ideas

  • Add Wi-Fi and send a push notification when leak is detected
  • Add multiple sensors on different GPIO ADC pins for multi-zone detection
  • Add a solenoid valve relay to cut main water supply automatically
  • Add an OLED showing which zone is wet and for how long

Real-World Applications

  • Sink cabinet leak alarm
  • Water heater drip monitor
  • Basement early warning sensor
  • Appliance overflow detector

Downloads

  • ESP32 Water Leak Detector Arduino sketchUse the code section as the source sketch.
  • Bench test checklistFollow the testing checklist before permanent installation.

FAQs

Can the sensor detect tiny droplets?

Only if the droplets bridge the sensor traces enough to change the reading. Test with small amounts of water before trusting a placement.

Where should I place the leak sensor?

Put it where water would reach early, such as the lowest point near a pipe, tray, or appliance base. A sensor placed too high may trigger too late.

What happens after the sensor dries?

The reading should fall back below the alarm threshold, but corrosion or residue can cause false alarms. Clean and dry the strip after wet tests.

Review, Testing, and References

Author: Abdul Mubeen and the ESP32 Engine editorial team. Last updated: 2026-07-05. Reviewed: wiring logic, Arduino code structure, beginner safety, and learning sequence.

Educational level: Beginner. Estimated completion time: 50-80 min. This project is for learning and prototyping; production or unattended hardware needs additional engineering review.

Project Complete!

You completed ESP32 Water Leak Detector as a real ESP32 engineering build, not just a wiring demo. You now know how to test the input, protect the circuit, explain the code, and improve the project safely.

  • Read and verify project input hardware
  • Map signals to safe ESP32 GPIO pins
  • Debug with Serial Monitor
  • Apply safety and performance checks
  • Plan the next learning step