Arduino - Water Sensor Pump
In this tutorial, we will learn how to use an Arduino to activate a pump for draining water when it is detected by a water sensor. In other words, we will be discovering how to create an automatic drainage system using an Arduino, a water sensor, and a pump
Hardware Required
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
About Water Sensor and Pump
If you do not know about water sensor and pump (pinout, how it works, how to program ...), learn about them in the following tutorials:
- Arduino - Water Sensor tutorial
- Arduino - controls pump tutorial
How the Automatic Drainage System Works
Arduino periodically reads the value from the water sensor, then:
- If the value is greater than a pre-defined threshold, Arduino turns on the relay to activate the pump.
- Otherwise, Arduino turns off the pump.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Code
Quick Steps
- 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
- Click Upload button on Arduino IDE to upload code to Arduino
- Embed the water sensor into the water
- See the pump's state
Code Explanation
Read the line-by-line explanation in comment lines of source code!
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.