Introduction: Solenoid Valve With Arduino Nano

About: An Open Source, Industrial Internet of Things (IIoT) and Unmanned Aerial Vehicles (UAVs) Enthusiast

The main intention of this project is to open and close a Solenoid Valve with Arduino Nano with a push button.
Courtesy: http://www.martyncurrey.com/

Supplies

Breadboard - 1 No.

Arduino Nano - 1 No.

Push button - 1 No.

10K Ohm Resistor - 1 No.

220 Ohm Resistor - 1 No.

2.2K Ohm Resistor - 1 No.

Red LED - 1 No.

TIP 120 - 1 No.

Diode - 1 No.

DC Female Jack - 2 Nos

Solenoid Valve - 1 No.

12V 1A DC Adapter - 1 No.

Step 1: A Brief Explanation and the Circuit

Using the Arduino to control the solenoid valve is simply a case of setting a pin high for the appropriate amount of time.

There is, however, a caveat, the solenoid works at a different voltage to the Arduino and you cannot directly connect the two. In this case a TIP120 transistor is used as a bridge. The TIP120 allows a small dc voltage (from the Arduino) to switch a larger dc voltage (12V to the solenoid). It can be thought of as a switch.

The diode connected to the solenoid allows current to flow only in one direction. When the current is turned off the solenoid tries to continue the current. This can fry the Arduino. The diode feeds this current back in to the solenoid until it is dissipated. In this post I am using DC voltage solenoid valves only.

I am attaching the complete Circuit diagram and following code helped me achieve the result. I tested opening and closing of solenoid valve by blowing air from one end. I now need to check connecting it to the water line.

Note: I am just an enthusiast and not a electronics professional. Reader may take help from this post and get it ratified by a professional before he/she attempts to build the same. I am very much in the learning phase all by myself sitting at home during COVID19 Lock-down.

Step 2: The Code

byte Valve = 2;

byte Switch = 3;

byte LED = 4;

boolean valveState = LOW;

boolean oldSwitchState = LOW;

boolean newSwitchState1 = LOW;

boolean newSwitchState2 = LOW;

boolean newSwitchState3 = LOW;

void setup()

{

pinMode(LED, OUTPUT);

pinMode(Valve, OUTPUT);

pinMode(Switch, INPUT);

}

void loop()

{

newSwitchState1 = digitalRead(Switch); delay(1);

newSwitchState2 = digitalRead(Switch); delay(1);

newSwitchState3 = digitalRead(Switch);

if ((newSwitchState1==newSwitchState2) && (newSwitchState1==newSwitchState3))

{

if ( newSwitchState1 != oldSwitchState )

{

oldSwitchState = newSwitchState1;

if ( newSwitchState1 == HIGH )

{

if (valveState==LOW)

{

valveState=HIGH;

digitalWrite(LED, HIGH);

digitalWrite(Valve, HIGH);

}

else

{

valveState=LOW;

digitalWrite(LED, LOW);

digitalWrite(Valve, LOW);

}

}

}

}

}