Arduino - Water/Liquid Valve
In this tutorial, we are going to learn how to control a liquid flow such as water, beer, oil by using Arduino and a solenoid valve. It is the same for controlling gas flow.
Or you can buy the following sensor kit:
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.
Solenoid Valve usually has two terminals:
Normally, the valve is closed. When 12V DC is applied to the two terminals, the valve opens and water/liquid can flow.
※ NOTE THAT:
For some kinds of valve, there is a gasket arrangement inside, so there is a minimum pressure requires to open the valve (after 12V DC is applied). The pressure can be created by liquid flow.
For some kinds of valve, liquid can only flow one direction.
If the valve is powered by 12V power supply, it opens. To control the valve, we need to use a relay in between Arduino and valve. Arduino can control the solenoid valve via the relay. If you do not know about relay (pinout, how it works, how to program ...), learn about relay in the Arduino - Relay tutorial

This image is created using Fritzing. Click to enlarge image
The below code repeatedly turns the water valve ON in five seconds and OFF in five seconds,
const int RELAY_PIN = A5;
void setup() {
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
digitalWrite(RELAY_PIN, HIGH);
delay(5000);
digitalWrite(RELAY_PIN, LOW);
delay(5000);
}
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
Check the water flow
Read the line-by-line explanation in comment lines of 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.
※ OUR MESSAGES
You can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!
Follow Us
Share with your friends!