How to Control a Solenoid Valve Using an Arduino Development Board

by Lisleapex Blog in Circuits > Arduino

180 Views, 0 Favorites, 0 Comments

How to Control a Solenoid Valve Using an Arduino Development Board

How to control a solenoid valve using an Arduino development board.png

Solenoid Valve is a very commonly used actuator in many process automation systems. There are many types of solenoid valves, such as those that can be used to open or close water or gas pipes, and electromagnetic plungers that are used to produce linear motion. A very common solenoid valve application that most of us will come across is the Ding Dong doorbell.


In this article, we will introduce in detail how to use the Arduino development board to control the solenoid valve.

Supplies

● Arduino UNO development board

● Solenoid valve

IRF540 MOSFET

● Button

● Resistor (10k, 100k)

● Diode 1N4007

● Breadboard

● Connecting wires

How Does a Solenoid Valve Work?

A solenoid valve is a device that converts electrical energy into mechanical energy. With a coil wrapped around a conductive material, the device acts as an electromagnet. The advantage of electromagnets over natural magnets is that they can be turned on or off when the coil needs to be energized. So when the coil is energized, according to Faraday's law, the current-carrying conductor has a magnetic field around it, and because the conductor is a coil, the magnetic field is strong enough to magnetize the material and create linear motion.


It works like a relay, with a coil inside that, when energized, pulls a conductive material (piston) into it, allowing liquid to flow. When power is removed, it uses a spring to push the piston back to its previous position and stop the flow of fluid again.


In this process, the coil requires a lot of current and creates hysteresis problems, so it is impossible to drive the electromagnetic coil directly through the logic circuit. Here we use a 12V solenoid valve, which is usually used to control liquid flow. The solenoid valve requires 700mA of continuous current when energized, with a peak value of nearly 1.2A, so we must consider these factors when designing the solenoid drive circuit for this particular solenoid valve.

Circuit Schematic

Circuit Schematic.png

The circuit diagram of using Arduino to control the solenoid valve is as follows

Programming Code Description

The complete code for Arduino to control the solenoid valve is given at the end of this article. Here we will explain the procedure a little bit to understand how the project works.


First, we define digital pin 9 as the output pin of the solenoid valve and digital pins 2 and 3 as the input pins of the button.

  1. void setup() {
  2.     pinMode(9, OUTPUT);
  3.     pinMode(2, INPUT);
  4.     pinMode(3, INPUT);
  5. }

In the loop() function, the solenoid valve is turned on or off based on the state of digital pins 2 and 3, which are connected to two buttons to turn the solenoid valve on and off.

  1. void loop() {
  2. if(digitalRead(2)==HIGH)
  3. {
  4.     digitalWrite(9,HIGH);
  5.     delay(1000);
  6. }
  7. else if(digitalRead(3)==HIGH)
  8. {
  9.     digitalWrite(9,LOW);
  10.     delay(1000);
  11. }
  12. }



Arduino Controls Solenoid Valve

Arduino Controls Solenoid Valve.png

After uploading the complete code to the Arduino board, you can turn the solenoid valve on and off with two buttons. The solenoid valve is also connected to an LED to indicate status.

When button 1 is pressed, the Arduino development board sends a HIGH level to the gate of the MOSFET IRF540, and the gate terminal is connected to the 9th pin of the Arduino. Since the IRF540 is an N-channel MOSFET, when its gate goes high, it allows current to flow from drain to source, thus opening the solenoid valve.

Similarly, when we press button 2, the Arduino sends a LOW level to the gate of the MOSFET IRF540, causing the solenoid valve to close.