Arduino Nano ESP32 - Water/Liquid Valve
This tutorial provides instructions on how to control a liquid flow such as water, beer, oil by using Arduino Nano ESP32 and a solenoid valve. It is the same for controlling gas flow.
|Arduino Nano ESP32
|USB Cable Type-C
|Liquid Solenoid Valve
|12V Power Adapter
|(Optional) DC Power Jack
|(Recommended) Screw Terminal Adapter for Arduino Nano
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
Overview of Water/Liquid Valve
Solenoid Valve usually has two terminals:
- Positive (+) pin (red): needs to be connected to 12V of DC power supply
- Negative (-) pin (black or other): needs to be connected to GND of DC power supply
How Water/Liquid Valve works
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.
How to Control Water/Liquid Solenoid Valve
If the valve is powered by 12V power supply, it opens. To control the valve, we need to use a relay in between Arduino Nano ESP32 and valve. Arduino Nano ESP32 can control the solenoid valve via the relay. Learn more about relay in the Arduino Nano ESP32 - Relay tutorial
This image is created using Fritzing. Click to enlarge image
Arduino Nano ESP32 Code
The below code repeatedly turns the water valve ON in five seconds and OFF in five seconds,
To get started with Arduino Nano ESP32, follow these steps:
- If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano ESP32) board and its corresponding COM port.* Copy the above code and paste it to Arduino IDE
- Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
- Check the water flow
The above Arduino Nano ESP32 code contains line-by-line explanation. Please read the comments in the code!