Controlling solenoids with arduino by jts3k
In this instructable we will be building a simple circuit that will allow us to control a solenoid using the popular physical computing platform arduino.  I became interested in controlling solenoids for robotic music applications.   A similar circuit can be used to control a motor or other devices that require more current than the arduino can provide directly from its output pins.  

Since the solenoid requires higher current than the arduino can provide we will be using an alternative power source for the solenoid (a couple batteries) and will be "driving" it with a TIP120 transistor.

The circuit we're using can be found online here.  This instructable draws from the excellent documentation in Tod Kurt's  bionic arduino workshops.

Build time was exactly one-beer.  Excluding the arduino and computer you use to program it, we are using less than $10 in parts.  Ok!

 
Remove these adsRemove these ads by Signing Up

Step 1: Parts

01-parts.jpg
• Arduino board
• USB cable for programming and powering the Arduino
• Breadboard 
• Some jumper cables
• A 1K resistor
• TIP120 transistor (TIP102 will also work fine)
• 1N4004 diode (1N4001 also works)
• Some batteries and connectors for solenoid power
• A solenoid with leads to connect to the breadboard
saleh jamal says: Apr 17, 2013. 1:18 PM
Hi ,
i have the same project,, but my solenoid only push and is difficult to get back ..
could you please post here the program code that u write to control the solenoid ..
thanks in advance
jts3k (author) says: Apr 17, 2013. 2:59 PM
That does not sound like it is an issue with your code. You need a spring or some other mechanism to pull the solenoid back. The solenoid can only pull in one direction so you'll need something mechanical to pull it back in the other direction. In this example I used a coiled up piece of wire to function as a spring pulling the shaft back out.
Lavanya Anand says: Feb 15, 2013. 10:43 PM
Hi

I purchased a solenoid valve . i want to control it from my arduino. I did not get
TIP 120/102 transistor. I got TIP 122 only. Can that be an alternative yo TIP 120? If yes is there any change i need to make with the above circuit? Please reply asap.

Regards
ddd1600 says: Dec 13, 2012. 4:11 PM
Which pin is the 1K resistor in. Is that pin 13?
ddd1600 says: Dec 13, 2012. 4:00 PM
Is there any difference between any of the three GND plugs on the Arduino?
aadot says: Oct 29, 2012. 1:52 PM
would you be so kind to point out exactly the type of insulated wire for the springs? im having the same problem, i need to fabricate springs for my solenoids...
laxplayer1199 says: May 30, 2011. 1:23 PM
How do you control how long the solenoid stays open? Thanks!
OCPik4chu says: Oct 15, 2012. 10:26 AM
He is using the basic sketch for a blinking light. Usually this sketch comes with the arduino software for free. The blinker sketch basically flips pin 13 from HIGH to LOW at an interval to blink an LED. In this case pin 13 goes to the solenoid so just modify the delay in the code to make it stay open longer, etc.

If you are looking at the sample code the line you need is:
digitalWrite(ledPin, HIGH);
delay(1000);

changing that delay (in miliseconds) will make it stay open longer.

If you need info on uploading or getting the sketch you can check a great tutorial here http://www.ladyada.net/learn/arduino/lesson1.html
4lifenerdfighter says: Jun 28, 2012. 12:14 PM
I always thought transistors were universally Emitter-Base-Collector.
jts3k (author) says: Jul 10, 2012. 8:56 AM
i'm not sure what's most common, but the TIP120 is definitely BCE - http://www.fairchildsemi.com/ds/TI/TIP120.pdf
4lifenerdfighter says: Jul 10, 2012. 9:55 AM
It might be because this transistor is in a voltage regulator style package instead of the normal half-cylinder. But I swear that to92 transistors are ebc.
plasma2002 says: Sep 7, 2011. 2:58 PM
You can just simply jump the grounds of different power supplies like that?
arphoto says: Jul 10, 2012. 7:32 AM
Yes you can.

This is only because it is the ground, which creates as he mentions a "common ground" which is needed when running to different power supplies on one system.

If you know anything about PCB design its essential the representation of having a ground plane and everything one the board being grounded to that plane while there could be more than one power supply input throughout the design.
3vilpenguin says: May 1, 2012. 1:06 PM
Is the reason it pulses because of your code? (ie. does the arduino alternate high and low?)

I want to implement this with a push button on/off.

Lastly, does it matter the mAh? I'd like to avoid using 9v batteries and instead use an AC adapter that outputs 12V natively
asyazrin says: Mar 1, 2011. 8:42 AM
what type solenoid used?
jts3k (author) says: Mar 1, 2011. 10:31 AM
I'm pretty sure it was this one:

http://www.goldmine-elec-products.com/prodinfo.asp?number=G16822

A "continuous duty" solenoid is preferable to "intermittent duty."
Poesis says: May 6, 2011. 7:30 AM
I bought some solenoids from that website and it didn't come with the springs are they included or was it something you got after to make the solenoid "spring" back?
jts3k (author) says: May 6, 2011. 8:38 AM
you'll need to fabricate some kind of spring to pull the shaft back out after the solenoid pulls it in. in this tutorial i just wrapped some insulated wire around the shaft to create a make-shift spring (you can see this in step 4 and the video in step 5).
kyle brinkerhoff says: Oct 28, 2010. 10:53 AM
hi there,
as someone who has used solenoid valves for many projects heres a little word of the wise: 1. use the exact same circuit to drive a small relay, wich will then control the current to the solenoid, this allows for two things, no kickback current, and a intermediate that will allow for a safety switch/ debug point. but yea your probably not going to be doing anything too dangerous to have to deal with these kind of problems but thats just the policy ive stuck to for many years.
but still great work!
steveastrouk says: Aug 28, 2010. 4:12 AM
As a generic instruction "a 1n4001" also works may well be wrong, because if you have a big enough solnoid, the back emf will destroy a 1N4001, or a 1N4004. A 1N 4007 may be better, but even then ALL the inductive kickback energy is dissipated in the resistance of the diode and the coil. In some circumstances even bigger diodes are needed.
davemsolomon says: Jun 4, 2010. 9:49 PM
Thank You! This answered my question on how to wire my TIP120.
peeley says: Apr 27, 2010. 4:19 PM
I had a basic problem but since this is basic stuff I think it might be helpful to someone else who stumbles across this. 

I have a very similar circuit set up except that it's not driving a solenoid and instead of 9V batteries I'm using a power supply to give the arduino 8.5V and using a voltage regulator circuit to bring 3V to the collector pin on the transistor, and I wanted 3V on the emitter when it was on.

I ran into trouble when the voltage on my emitter pin was a good 0.7V lower than the voltage on the collector. This seems like a lot when we are dealing with voltages in the single digits ... I think this transistor is designed for higher voltage/current, but we have to work with what we have :)

To solve this, I had to realize that like it or not I had created a voltage divider. I found there was about a 100 ohm resistance between the C and E pins in the TIP120 when it was "on" and about 365 ohms in my load. I drew a little voltage divider circuit, filled in my known values and solved for the input voltage I needed to get 3V at the middle node of my accidental voltage divider.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!