Arduino Nano - Water/Liquid Valve
This tutorial instructs you how to use an Arduino Nano and a solenoid valve to control the flow of liquids such as water, beer, and oil. The same principles apply for controlling the flow of gas.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of Water/Liquid Valve
The Water/Liquid Valve Pinout
A solenoid valve typically has two terminals:
- The Positive (+) pin (which is usually red) should be connected to the 12V of a DC power supply
- The Negative (-) pin (which is usually black or another color) should be connected to the GND of a DC power supply
How Water/Liquid Valve works
Typically, the valve is shut. When 12V DC is supplied to the two terminals, the valve opens and liquid/water can pass through.
※ NOTE THAT:
- A gasket arrangement is inside, so a minimum pressure is necessary to open the valve after 12V DC is applied. This pressure can be generated by the flow of liquid.
How to Control Water/Liquid Solenoid Valve using Arduino Nano
If the valve is powered by a 12V power supply, it will open. In order to control the valve, a relay needs to be used between Arduino Nano and the valve. The solenoid valve can be managed by Arduino Nano through the relay.
If you are not familiar with relays (pinout, how it works, how to program, etc.), please refer to the Arduino Nano - Relay tutorial for more information.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Nano Code for Controlling Liquid Valve
The code below turns the water valve ON for five seconds and OFF for five seconds.
Detailed Instructions
- Plug the USB cable into the Arduino Nano and the PC.
- Open the Arduino IDE, select the appropriate board and port.
- Copy the code and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and upload the code to the Arduino Nano.
- Measure the water flow rate.
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!