Arduino - Water Leak Detector

In this guide, we will learn to use the Arduino and a water leak sensor to find water leaks.

Hardware Required

1×Arduino Uno
1×USB 2.0 cable type A/B
1×Water Leak Detector
1×Breadboard
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

About Water Leak Detector

The water leak detector, or water leak sensor, helps us find any unwanted water early to avoid possible damage.

Water Leak Detector Pinout

The water leak detector comes with two wires:

Water Leak Sensor Pinout

Just like a switch or button, we don't need to tell the difference between the two wires of the water leak detector.

How the Water Leak Detector Works

When there is water, the circuit closes. When there is no water, the circuit stays open.

To set up the water leak detector with an Arduino, connect one wire to GND and the other wire to an input pin on the Arduino configured as a digital input pull-up. If there is water, the Arduino pin will show a LOW value. If there is no water, the pin will show a HIGH value.

※ NOTE THAT:

The water leak detector cannot detect "non-conductive" water like pure water. To make it work, scatter some salt near the sensor. The water will mix with the salt, making the water conductive.

Wiring Diagram between Water Leak Detector and Arduino

Arduino water leak detector wiring diagram

This image is created using Fritzing. Click to enlarge image

How To Program Arduino to read value from Water Leak Detector

  • Set the Arduino pin as a digital input by using the pinMode() function. For instance, for pin D7, use this function.
pinMode(7, INPUT_PULLUP);
  • Uses the digitalRead() function to check the condition of the Arduino pin.
int water_state = digitalRead(7);

Arduino Code - Detecting Water Leakage

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-water-leak-detector */ #define WATER_SENSOR_PIN 7 // Arduino pin D7 connected to water sensor's pin int water_state; // current state of water sensor int prev_water_state; // previous state of water sensor void setup() { Serial.begin(9600); pinMode(WATER_SENSOR_PIN, INPUT_PULLUP); // set Arduino pin to input pull-up mode water_state = digitalRead(WATER_SENSOR_PIN); // read state } void loop() { prev_water_state = water_state; // save the last state water_state = digitalRead(WATER_SENSOR_PIN); // read new state if (prev_water_state == HIGH && water_state == LOW) { Serial.println("Water leakage is detected!"); } }

Quick Steps

  • Copy the code above and paste it into the Arduino IDE.
  • To upload the code to your Arduino board, click the Upload button in Arduino IDE.
  • Pour water near the water leak detector.
  • Check the results on the Serial Monitor. It appears as follows:.
COM6
Send
The water leak is detected The water leak is detected
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES