How to Control a Solenoid Valve Using Arduino

by Utsource in Circuits > Arduino

249 Views, 0 Favorites, 0 Comments

How to Control a Solenoid Valve Using Arduino

Screenshot_20191227-010041__01.jpg
Hi guys in this instructables we will learn how to use solenoid valve using Arduino.
So this Tutorial will illustrate the method to control a solenoid value with Arduino uno.

Things You Need

Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png
Solenoid-Valve.png

For this instructables we will need following things :

Arduino UNO


Solenoid Valve


IRF540 MOSFET


Pushbutton – 2 nos.


Resistor (10k, 100k)


Diode – 1N4007


Breadboard


Connecting Wires

Schmatics

Circuit-Diagram-for-controlling-a-Solenoid-Valve-with-Arduino.png
The schmatics is very simple so please follow the shown schmatics and connect all components according to the shown schmatics.

Code

20191121_193959.jpg
Please copy the following code and upload it to the arduino Board :

void setup() {
pinMode(9, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
}
void loop() {
if(digitalRead(2)==HIGH)
{
digitalWrite(9,HIGH);
delay(1000);
}
else if(digitalRead(3)==HIGH)
{
digitalWrite(9,LOW);
delay(1000);
}
}

Controlling Solenoid Valve

Circuit-Hardware-for-controlling-a-Solenoid-Valve-with-Arduino.jpg
Screenshot_20191227-010055__01.jpg
Screenshot_20191227-010044__01.jpg
Screenshot_20191227-010041__01.jpg
After uploading complete code into the Arduino, you will be able to turn on and off the solenoid with the help of two push buttons. An LED is also attached with solenoid for indication purpose.



When button 1 is pressed, Arduino send a HIGH logic to gate terminal of the MOSFET IRF540, connected on the 9th pin of the Arduino. As IRF540 is an N-Channel MOSFET, so when its gate terminal gets HIGH, it allow the flow of current from drain to source and turn the solenoid on.

Similarly, when we press the button 2, Arduino sends a LOW logic to the gate terminal of the MOSFET IRF540 which makes the solenoid turn off.