Make three smart water leak detectors for less than $20

Once, on a beautiful Saturday morning, I heard a loud pop sound in the house. Suddenly, our cat, Mirella, was acting weird. She arched her back and started walking in circles near the basement entrance. When I approached her, she led me downstairs. That’s when I found nearly an inch of water in the basement. The pop sound was the backflow preventer valve exploding. 

Due to Mirella’s insistence, there was no permanent damage. Sure, Saturday was completely ruined. But it was still a better outcome than extensive damage, restoration, or mold cleanup. A couple of hours of mopping and additional ventilation brought the basement back in working order.

Since then, I have been obsessed with detecting leaks in the basement. With the amount of plumbing in my basement, it’s only a matter of time until another leak springs another surprise. There are too many points of failure in this old house. It could be a busted heating system, leaky laundry machine, or an overflow in the bathroom. 

Selecting the right water leak detector

The first thing I bought was a 110 dB battery-operated water alarm. But the battery required extra monitoring from me. Also, a loud alarm causes so much stress to our pets but will never reach me when I’m away from the house. So that solution was not sufficient.

Then I looked into systems with whole house water shut-offs. But they still relied on regular sensors to detect water. They required a professional plumber to install. They are expensive. So, in the end, the water shutoff system was an unnecessary add-on. 

Finally, I decided to tinker with my sensors to build a water detection system that is: highly configurable, inexpensive and sends smart notifications. I made such a system, so let me share with you how it looks.

Microcontroller ESP8266 3 pack
ESP8266 3 pack

Here’s easy to program microcontroller that’s also WiFi-enabled. It can work off a battery pack or simply plug it into a switch. It comes in a pack of three. Create three separate water detectors for a heating system, a laundry machine, and a bathroom.

5PCS Water Level Sensor Liquid Water Droplet Depth Detection Sensor

Here’s a pack of water detecting sensors. They offer a great way to detect a leak, spill, flood, rain, etc. Use them to check for the presence, level, volume, or absence of water. The sensor has an array of exposed traces, which indicate LOW when water is detected.

Wiring Diagram for Water Leak Detector

Putting them together is simple. I chose to power the sensor with the VIN pin to give it close to 5v of power. However, this setup can still work with drawing 3.3v power to the sensor. Then, connect the S (signal) pin to A0 (analog) on the microcontroller. 

Note: Yes, I know that three microcontrollers and 5 sensors don’t match up. But neither does a 10 pack of hot dogs and an 8 pack of hot dog buns. 

Program the device (with Zentser)

There are two main steps to tie your hardware to a smart cloud-enabled mobile app. 

1. Partition the device in Zentser

Download the Zentser app (iOS or Android.) Sign up. Create a new device. Then copy the certificates and IDs for your partitioned device to be used in coding later.

Zentser screen with needed code
2. Flash your device with custom code

In Arduino IDE (download), go to Tools > Manage Libraries. Install ‘Zentser ESP SDK’ and its dependencies.

Arduino steps to install package

Then you can use the following code. Make sure to replace the WiFi credentials with your SSID and password. Then replace the certificates and IDs that you got from a step above and paste it between the “// --- START ---” and “// --- END ---” lines.

/*#include */

const int analogInPin = A0;

int sensorValue = 0;
int sensorPercentValue = 0;

char const *ssid = "YOUR_WIFI";
char const *wiFiPassword = "YOUR_WIFI_PASSWORD";

// Replace on generated code from Zentser Application
// --- START ---
static const char caCert[] PROGMEM = R"EOF(

static const char cert[] PROGMEM = R"KEY(

static const char privateKey[] PROGMEM = R"KEY(

String deviceId = "YOUR_DEVICE_ID"; // Zentser Device ID
String sensorId = "YOUR_SENSOR_ID"; // Zentser Sensor ID

// --- END ---

AWSConfig aws = AWSConfig(deviceId, sensorId); // init AWS function

// Function to connect to WiFi
void connectToWiFi() {
Serial.print("\nConnecting to AP ...");

WiFi.begin(ssid, wiFiPassword);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("\nConnected to AP");

// initial function at starting your microcontroller (ESP, Arduino, etc)
void setup() {
Serial.begin(115200); // init serial for logging

connectToWiFi(); // call function to start WiFi connection

//get AWS certificates to authenticate sending sensor data
aws.setupAWSCertificates(cert, privateKey, caCert);


// main loop for microcontroller where you will collect and send sensor data
void loop() {

// Check Wifi connection is still active
if (WiFi.status() != WL_CONNECTED) {

// MODIFY to get sensor readings from hardware connected to your microcontroller
sensorValue = analogRead(analogInPin);
sensorPercentValue = map(sensorValue, 0, 1023, 0, 100);
Serial.printf("sensorValue = %i\n", sensorValue);
Serial.printf("sensorPercentValue = %i\n", sensorPercentValue);


// check that we're not bombarding Zentser with too much data
// don't want to bring the system down in unintended DDoS attack

After you compile and upload the code, you should see in Serial Monitor that the device is sending information. 

Flash the microcontroller

Now just repeat the steps for creating a Leak Detector Device number two and number three.

Configure and Test

This is the final fun part. It’s where you get to see your creation come to life. 

Go into the Zentser app, you should see some latest values recorded from your Leak Detector. In the perfect dry environment, you should see a meager presence of water (less than 5%.) 

Set up thresholds for notifications
Set up thresholds for notifications

Set up the alert to notify you when the sensor reads a value over 5%. If you placed the sensor in a dry place, it should trigger a warning in case there’s even a milliliter of water. I mean, in case there’s even a 1/32 of an inch of water. 

You can see a simple test. Then after you see the triggered warning, wipe everything, including the sensor. That’s it. You should be good to go.

If you found value in this project or want me to improve it even more, let's talk directly on the official Reddit page

Looking forward to your feedback!

For updates on advance measuring techniques and sensors, please sign up for our list
Thanks for signing up! We will send you informative content on how to use sensors to make your life better!
Oops! Something went wrong while submitting the form.
Latest POSTS
Copyrights © | All rights reserved.