Arduino Nano - Water Leak Detector

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

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×Water Leak Detector
1×Breadboard
1×Jumper Wires
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of Water Leak Detector

The water leak detector or sensor can find unwanted water early to prevent damage.

Water Leak Detector Pinout

The water leak detector includes two wires:

Water Leak Sensor Pinout

Just like a switch or button, we don’t have to identify the difference between the two wires in the water leak detector.

How the Water Leak Detector Works

When water is present, the circuit becomes complete. When there is no water, the circuit remains open.

To connect a water leak detector to an Arduino Nano, attach one wire to the GND and the other wire to a digital input pin set as a pull-up. When water is present, this pin on the Arduino Nano will read as LOW. If there is no water, it will read as HIGH.

※ NOTE THAT:

The water leak detector cannot sense pure water because it does not conduct electricity. To solve this, sprinkle some salt close to the sensor. The salt will mix with the water and allow the detector to sense it.

Wiring Diagram between Water Leak Detector and Arduino Nano

The wiring diagram between Arduino Nano and water leak detector

This image is created using Fritzing. Click to enlarge image

How To Program Arduino Nano to read value from Water Leak Detector

  • Use the pinMode() function to set the Arduino Nano pin as a digital input. For example, use it for pin D4.
pinMode(4, INPUT_PULLUP);
  • Uses the digitalRead() function to examine the status of the Arduino Nano pin.
int water_state = digitalRead(4);

Arduino Nano Code - Detecting Water Leakage

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-water-leak-detector */ #define WATER_SENSOR_PIN 4 // Arduino pin D4 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!"); } }

Detailed Instructions

  • Copy the code above and paste it into the Arduino IDE.
  • To uoload the code to your Arduino Nano board, click the Upload button in the Arduino IDE.
  • Pour water close to the water leak detector.
  • Look at the results on the Serial Monitor. It will show like this:.
COM6
Send
The water leak is detected The water leak is detected
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!