Arduino - Water Sensor Relay
In this tutorial, we will learn how to use an Arduino to activate a relay when it detects water. Then you can connect the relay to a pump, or a siren, buzzer to make a water alarm.
Or you can buy the following sensor kit:
|1||×||DIYables Sensor Kit 30 types, 69 units|
About Water Sensor and Relay
If you do not know about water sensor and relay (pinout, how it works, how to program ...), learn about them in the following tutorials:
How It Works
Arduino periodically reads the value from the water sensor. If the value exceeds a pre-defined threshold, the Arduino activates the relay; otherwise, it deactivates the relay.
This image is created using Fritzing. Click to enlarge image
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- Copy the above code and open with Arduino IDE
- Update the value of THRESHOLD in the code to a suitable value for your application
- Click Upload button on Arduino IDE to upload code to Arduino
- Embed the water sensor into the water
- See the relay's state
Read the line-by-line explanation in comment lines of source code!
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.