Solenoid valve control using arduino

Solenoid Valve

A solenoid valve is an electromechanical valve used to control the flow of fluids. It has a simple valve Open and Close mechanism operated by a solenoid.

Solenoid valves are widely used in various appliances and devices, such as washing machine, automatic irrigation system, filling machine, etc.

Working of a Solenoid valve

In connection wise and operation wise, a solenoid valve is similar to a relay. Both devices are operated by an electromagnetic force applied to a movable contact.

A basic solenoid valve consists of a solenoid, plunger, spring and valve body. The valve can be either Normally Open or Normally Closed.

In a normally closed valve,  if no charge is applied to the coil the valve remains in a closed position. Similarly, a normally open valve remains open until an electric supply is applied to the solenoid.

When an electric current is passed through the solenoid it generates a magnetic field. By the magnetic force the plunger or core made up of a ferromagnetic material will be pulled. And when the coil is de-energized, the spring push back the plunger and holds the normal position in the absence of magnetic force.

Arduino solenoid valve control circuit

Here shows the simple arrangement to interface a solenoid valve with arduino.

arduino solenoid valve controlling

DC Solenoid valves are available with 6V, 12V, 24V, 120V, 240V operating voltages. Here circuit has a 12V DC solenoid and it is powered by an external supply. The transistor switches the Solenoid supply with respect to the Output of the Arduino.

The Diode 1N4007 in the circuit is used as a flyback or flywheel diode which is similar to used in relays, coils or inductive loads. The catch diode eliminates sudden voltage spike occurs across the coil during a switch off. Even though it is recommended to interface the arduino and solenoid circuits via an optocoupler.

The solenoid valve can be connected to arduino also by interfacing with a relay module. As most modules have inbuilt optocoupler,  they can ensure complete isolation of the arduino board from external circuits. This is method is more better than a direct transistor biasing circuit. Also relay interface can operate solenoid valves of wide operating voltage ranges.


// Code to Open and close an NC valve in 5 seconds gap.
int valvepin = 2;

void setup() {
  pinMode(valvepin, OUTPUT);

void loop() {
  //Opens the valve for 5 seconds
  digitalWrite(valvepin, HIGH);
  //Close the valve for 5 seconds
  digitalWrite(valvepin, LOW);

11 Responses

  1. Raj says:

    Hi i wana made ir senaor to control 230 volt solenoid for hand wash tape .what wil be reliable method

    • admin says:

      Use a relay module to operate the solenoid valve, as the solenoid valve has a voltage of 230v. For IR, just use an IR proximity sensor circuit.

  2. Cole says:

    What type of resistor is that for the first diagram?

  3. Lakshmi Kanth says:

    I am using 24v solenoid valve to control pneumatic bumper does aurdino is required for that

  4. Jorge says:

    hello, how do I control a proportional valve, it is 24 v starting at 30 mA up to 150 mA, which circuit can I use to control it!?

    • admin says:

      You can use a current-controlled amplifier or power supply circuit to provide the control signal to the valve, where the output current is controlled by an input signal. You could use a module similar to the motor driver and use the Arduino to send digital signals to the driver circuit to control the valve’s flow rate. You can adjust the flow rate by changing the duty cycle of the PWM signal or by changing the direction of the current in the H-bridge circuit of the driver.

  5. anass boupouchi says:

    can you please tell me what is that tiny black square located between (valve, power supply and the relay) and can you give me references (serial number or anything)
    thank you

    • admin says:

      Nothing just a connector. You could skip that and assume a direct connection, positive through the relay and negative from the power supply.

  6. Aman says:

    Hi,i am using 24v solenoid valve to stop and allow gas(oxygen) with 1 sec delay so can i use 2nd circuit?

Leave a Reply

Your email address will not be published. Required fields are marked *