Projects / Water leak detector with phone alert

Water leak detector with phone alert

Beginner1 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ESP32

    Wire the sensor

    VCC to GPIO 4, GND to ground, S to GPIO 3 and the buzzer to GPIO 5.

  2. ESP32

    Read it dry and wet

    Upload and open the serial monitor. Note the reading dry, then touch the strip with a damp finger.

  3. ESP32

    Set the threshold

    Put WET between the dry and the wet readings.

  4. ESP32

    Install ntfy on your phone

    Subscribe to your own random topic name and put the same URL in the code.

  5. ESP32

    Place the sensor

    Lay the strip flat on the floor where leaks collect, with the electronics higher up and dry.

  6. ESP32

    Test with a few drops

    The buzzer sounds and the phone gets an alert. Dry it and it stops.

In short

How do you build a water leak detector with phone alert?

A sensor under the washing machine or RO purifier sends a phone alert the moment water appears on the floor. You need ESP32-C3 SuperMini, Water level sensor module, Active buzzer 5 V, USB A to USB-C cable (data), 5 V 2 A USB adapter and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Sensor VCCESP32-C3 GPIO 4Powered only while reading, so the traces do not corrode
Sensor GNDGNDGround
Sensor S (signal)GPIO 3Analog input
Buzzer +GPIO 5Alarm
Buzzer -GNDReturn
PowerUSB-C adapter5 V

Code

Arduino IDE with the ESP32 board package by Espressif, board "ESP32C3 Dev Module". The code sends a plain message to ntfy.sh, a free notification service: install the ntfy app on your phone and subscribe to the same topic name. Use a long random topic name, and do not put personal information in the message. Do not hard-code your Wi-Fi password in a project you share.

Runs on a virtual ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <WiFi.h>
#include <HTTPClient.h>

const char *SSID = "your-wifi", *PASS = "your-password";
const char *TOPIC_URL = "http://ntfy.sh/your-long-random-topic";   // pick a long random name, anyone who knows it can read it
const byte POWER = 4, SENSE = 3, BUZZ = 5;
const int WET = 800;                       // above this reading counts as wet: set it from your own readings
unsigned long lastAlert = 0;

int readSensor() {
  digitalWrite(POWER, HIGH); delay(50);
  int v = analogRead(SENSE);
  digitalWrite(POWER, LOW);
  return v;
}

void alert() {
  HTTPClient http;
  http.begin(TOPIC_URL);
  http.POST("Water leak detected");
  http.end();
}

void setup() {
  pinMode(POWER, OUTPUT); pinMode(BUZZ, OUTPUT);
  Serial.begin(115200);
  WiFi.begin(SSID, PASS);
  while (WiFi.status() != WL_CONNECTED) delay(500);
}

void loop() {
  int v = readSensor();
  Serial.println(v);
  if (v > WET) {
    digitalWrite(BUZZ, HIGH);
    if (lastAlert == 0 || millis() - lastAlert > 300000UL) { alert(); lastAlert = millis(); }   // repeat every 5 minutes
  } else {
    digitalWrite(BUZZ, LOW); lastAlert = 0;
  }
  delay(2000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32-C3 DevKitM-1 with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

819
820
819

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Dry stripReading near zero
Drops of waterReading rises above the threshold and the buzzer sounds
Phone alertArrives within seconds
Water left on the stripA repeat alert every 5 minutes

If it does not work

No phone alert

Wi-Fi did not connect, or the topic name differs between app and code.

Reading never changes

Check the sensor is powered through GPIO 4 and signal on GPIO 3.

Strip corrodes

It was powered all the time. Keep the pulsed power as in the code.

False alarms

Humidity or dust. Raise the threshold slightly.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the water leak detector with phone alert?

ESP32-C3 SuperMini, Water level sensor module, Active buzzer 5 V, USB A to USB-C cable (data), 5 V 2 A USB adapter and Jumper wires male to male (40 pcs, 20 cm).

How long does the water leak detector with phone alert take to build?

About 60 minutes for a beginner maker, in 6 steps.

How do I know the water leak detector with phone alert works?

Dry strip: Reading near zero. Drops of water: Reading rises above the threshold and the buzzer sounds. Phone alert: Arrives within seconds.

No phone alert: what should I check?

Wi-Fi did not connect, or the topic name differs between app and code.

Reading never changes: what should I check?

Check the sensor is powered through GPIO 4 and signal on GPIO 3.

Strip corrodes: what should I check?

It was powered all the time. Keep the pulsed power as in the code.

False alarms: what should I check?

Humidity or dust. Raise the threshold slightly.