ESP8266 - Water Leak Detector
In this guide, we will learn how to use an ESP8266 and a water leak sensor to detect water leaks.
Hardware Preparation
1 | × | ESP8266 NodeMCU | |
1 | × | Micro USB Cable | |
1 | × | Water Leak Detector | |
1 | × | Breadboard | |
1 | × | Jumper Wires | |
1 | × | (Optional) Screw Terminal Expansion Board for ESP8266 |
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Overview of Water Leak Detector
The water leak detector, also called a water leak sensor, helps us discover unwanted water early to prevent damage.
Water Leak Detector Pinout
The water leak detector includes two wires:
![Water Leak Sensor Pinout](https://newbiely.com/images/tutorial/water-leak-sensor-pinout.jpg)
We don't have to distinguish between the two wires of the water leak detector, just like we don't need to differentiate between a switch and a button.
How the Water Leak Detector Works
When water is present, the circuit becomes complete. When there is no water, the circuit remains incomplete.
To connect the water leak detector to an ESP8266, attach one wire to the GND and the other to a digital input pin on the ESP8266 set as a pull-up. When water is present, the pin reads LOW. Without water, it reads HIGH.
※ NOTE THAT:
The water leak detector cannot sense pure water because it is "non-conductive." To fix this, sprinkle some salt near the sensor. This will mix with the water and allow the detector to recognize the water.
Wiring Diagram between Water Leak Detector and ESP8266
![The wiring diagram between ESP8266 NodeMCU and water leak detector](https://newbiely.com/images/tutorial/esp8266-water-leak-sensor-wiring-diagram.jpg)
This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
How To Program ESP8266 to read value from Water Leak Detector
- Configure the ESP8266 pin as a digital input with the pinMode() function. For example, use this function for pin D7.
- Checks the condition of the ESP8266 pin using the digitalRead() function.
ESP8266 Code - Detecting Water Leakage
Detailed Instructions
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Copy the code above and paste it into the Arduino IDE.
- To upload the code to your ESP8266 board, click the Upload button in Arduino IDE.
- Pour water close to the water leak detector.
- See the results on the Serial Monitor. They will display like this: