Arduino UNO R4 - Water/Liquid Valve

In this tutorial, we will learn how to control the flow of liquids like water, beer, and oil using an Arduino UNO R4 and a solenoid valve. In detail, we will learn:

Arduino UNO R4 Water/Liquid Valve

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×Relay
1×Liquid Solenoid Valve
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino UNO R4
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of Water/Liquid Valve

Pinout

Arduino UNO R4 Water/Liquid Valve Pinout

A solenoid valve typically has two connections.

  • Connect the positive (+) pin (red) to the 12V DC power supply.
  • Connect the negative (-) pin (black or other) to the GND of the DC power supply.

How Water/Liquid Valve works

Usually, the valve is shut. When 12V DC is connected to the two points, the valve opens, allowing water or other liquids to pass through.

※ NOTE THAT:

Some valves have a gasket inside, and they need a minimum pressure to open after applying 12V DC. This pressure can be generated by the flow of liquid. Additionally, some valves allow liquid to flow in only one direction.

How to Control Water/Liquid Solenoid Valve

When the valve receives 12V power, it opens. To manage the valve, a relay is required between the Arduino UNO R4 and the valve. The Arduino UNO R4 uses the relay to operate the solenoid valve. If you are unfamiliar with how a relay functions, its pin configuration, or how to program it, you should read the Arduino UNO R4 - Relay tutorial.

Wiring Diagram

The wiring diagram between Arduino UNO R4 water valve

This image is created using Fritzing. Click to enlarge image

Arduino UNO R4 Code

This code will turn the water valve ON for five seconds and then turn it OFF for five.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-water-liquid-valve */ #define RELAY_PIN 3 // The Arduino UNO R4 pin connected to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // open valve 5 seconds delay(5000); digitalWrite(RELAY_PIN, LOW); // close valve 5 seconds delay(5000); }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect the Arduino Uno R4 to the water valve according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the provided code and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to transfer the code to the Arduino UNO R4.
  • Monitor the water flow.

Code Explanation

The explanation is available in the comments within the provided Arduino code.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!