How to Control a Solenoid Valve Using Arduino

Introduction: 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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Things You Need

For this instructables we will need following things :

Arduino UNO

Solenoid Valve


Pushbutton – 2 nos.

Resistor (10k, 100k)

Diode – 1N4007


Connecting Wires

Step 2: Schmatics

The schmatics is very simple so please follow the shown schmatics and connect all components according to the shown schmatics.

Step 3: 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() {
else if(digitalRead(3)==HIGH)

Step 4: 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.

Be the First to Share


    • Tiny Speed Challenge

      Tiny Speed Challenge
    • Clocks Contest

      Clocks Contest
    • PCB Design Challenge

      PCB Design Challenge