Controlling a Solenoid Valve from an Arduino

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.

TIP120

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, applying a current to  B allows current to flow between C to E.

Connecting a solenoid to an Arduino

Solenoid Circuit

The diode (a 1N4007 in this case) 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.

Here is the circuit on a breadboard.
Solenoid circuit on breadboard

You can get more information about connecting a solenoid at
http://playground.arduino.cc/Learning/SolenoidTutorial
http://bildr.org/2011/03/high-power-control-with-arduino-and-tip120/

 

31 thoughts on “Controlling a Solenoid Valve from an Arduino

    • To open the solenoid you just need to set the Arduino pin connected to the TIP120 HIGH. It is the same as turning on a LED which you can see in the Blink sketch.

  1. Can you please send by e-mail me the code for this script Controlling a Solenoid Valve from an Arduino | Martyn Currey or please inform me in detail about this script?

  2. Hi Martyn,
    I have tried your example but it’s not working with my water pump.
    I’m using Arduino, 2.2K resistor, TIP120, water pump (3.5-9V 1-3W), 9V AC adapter.
    Everything connected as on your diagram.
    * when I connect pump directly to 9V, it’s working
    * when connect through transistor, it’s not. However when I connect multimeter instead of water pump, I see that transistor is opened.

    Do you have any idea, why it’s not working?

    • Hi Oleg,
      Is the 9V AC adaptor powering the water pump? The TIP120 can only be used for DC, not AC. If the pump is AC then look at using a relay instead. The Arduino would turn the relay on and off and the relay would allow current to the pump.

      When picking a relay be careful about how much current it will draw. The Arduino can safety provide 40 mA only. Many relays will draw more than this.

        • A few of things I would suggest.

          1. Redo all the wires and check all the connections.

          2. remove the Arduino. Connect the wire that goes to the Arduino digital pin directly to 5V (still needs the 2.2K resistor). If the pump works then the problem is with the Arduino, either the hardware or more likely with your sketch.

          3. Test the TIP120 with an LED. Replace the pump with an LED (inline with a 1K ohm resistor). See if you can get the LED to turn on and off. Once you have confirmed the TIP120 is working you can work on getting the pump to work.

          • Ok, I have connected diode + 1K resistor instead of pump. Diode is working fine.
            But pump sometimes works, but sometimes not. When I connect it directly to DC, it works. Then I connect it to my pcb, it works few times (3-7 times) and then it stops, but still I can see new “Pump!” messages in serial monitor. Then again I need to connect it directly to DC to make it live.

            Here is my code:
            http://paste.ofcode.org/3XyMUzF35hJbuBC2YYiyf3

  3. Probably my DC adapter is too weak (300mA). I have connected my pcb + pump to 9V battery and it’s working without problems. Need to find better adapter :)

  4. Pingback: How to make a mechanic synth, Autotel

  5. Im trying to use my arduino UNO to send a +5V signal to a mosfet to drive a 24V solenoid. i know that i need a diode across the solenoid to protect it. What i don’t know is how to pick the right mosfet. I know that i needs to be logic compatible. My power supply is 24VAC 750mA. the in rush current of the solenoid is 0.35A @ 24 VAC. The holding current is 0.23A @ 24VAC.

  6. Nice circuit. However, I would like to add a led between arduino digital pin and transistor, so to easily watch pin status in the board. Thank you :)

  7. I’m a software guy, so electronics is not my strengh. What if I would want to control several solenoids with an Arduino and several shift registers (74HC595) how would the circuit change with a led between shift register and transistor? Thanks again, your doc has helped me already a lot.

    • The resistor is used to limit the current. Without it the transistor would try to draw more current than it really requires which would likely damage the Arduino, the transistor, or both.

Leave a Reply

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


nine − 4 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>