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
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.
So this Tutorial will illustrate the method to control a solenoid value with Arduino uno.
Things You Need
For this instructables we will need following things :
Arduino UNO
Pushbutton – 2 nos.
Resistor (10k, 100k)
Schmatics
The schmatics is very simple so please follow the shown schmatics and connect all components according to the shown schmatics.
Code
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);
}
}
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
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.
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.