Help wiring up a solenoid to the arduino...

I need help figuring out how to wire a single solenoid to the arduino. I saw the tutorial on this site, but it's giving me a headache with the circuit diagram and all the extra parts. I'm just looking for a basic circuit to protect my arduino, something for a beginner. From what I can tell on other searches, I just need a transistor to drive the solenoid, and then a diode connected to both sides of the solenoid for protection when the solenoid is switched off. My questions are: How to chose the right transistor and how to chose the right diode? Here are the specs from the description of the solenoid I'll be using:

"Operates from 12VDC to 24VDC. Coil resistance is 3.3 to 4.2 ohms. At 24VDC, the pull force is 3.7 lbs."

Do you want to operate it at 12V or 24V?

That is a big solenoid. :o

At 24V with a resistance of 3R3 you have a current of 24/3.3 = 7.2Amps!

That is massive, it will need a big supply and probably a big FET to switch it rather than a transistor. Make sure it is a logic level FET that can handle at least 20A.

Does your project require one this large?

If you are only testing, it might be smart to just buy a 5v solenoid for your arduino. It depends on the use of it of course but if you search on youtube you will find some pretty awesome projects with small solenoids :slight_smile:

[example]

Was planning on running it at 12v. The solenoid will be used to push a physical lever and I could probably get away with a smaller one. I also have this one:

"Operates on 9VDC up to 24VDC. Coil resistance is 46[ch937]. Has flexible wire leads terminating in a standard 2 pin male connector.
G16829 "

I had a hard time finding a small solenoid online, but maybe that's just because I'm not very familiar with the specs or what to look/search for. Where would I find a 5v solenoid?

Where would I find a 5v solenoid?

Look here for a start:-

So, correct me if I'm wrong, if I go with the other solenoid I have list above, which is 9V/46[ch937], then my current will be around 196mA, seems more reasonable, as this project will eventually be running from a set of batteries. I still need to know how to chose the right diode and transistor though, how to I choose the specs?

Since you're buying from Goldmine, this is one of the few logic-level power FETs they sell, and should work for you. I used a diode pair similar to this one for my solenoid driver board, but I got it from BG Micro.

I have to disagree with the notion of using 5V solenoids: they're not that available at surplus prices, and you have to switch a lot more current to get an amount of push/pull comparable to 12V or 24V ones. You could drive up to seven of those lighter-duty 12V ones from Goldmine you cited with a simple-to-use, low-cost ULN2003, as long as you were only firing one or two at a time, and keeping the average load down.

To allow for higher peak currents that occur when you first (de-)energize loads like solenoids, I usually look for a rating of about 3-5 times the nominal current, but I'm a software guy by profession, so I'm sure some hardware types would say I'm being over-cautious. Since I'm usually designing for one- or two-unit "production runs", and the cost difference at surplus prices is usually pennies, I use a "better safe than sorry" rule. :wink:

Step one: determine the drive voltage you'll be using, it must be in the range the solenoid can handle.

Step two: determine the current from the resistance of the solenoid and ohms law.

Step three: the diode must be able to handle the current and voltage, but otherwise is not critical - its only a transient current. Allow a 50% safety factor on the ratings if possible.

Step four: the transistor/FET must be rated for the supply voltage, again allow 50% margin. For bipolar transistor the Vcbo and Vceo should both be big enough.

Step five: the transistor/FET must comfortably handle the current and power. Since this is a switching application the power rating is unlikely to be crucial as the device with either be off (no current) or on (very little voltage). Given the voltage and current ratings find some candidate devices from your supplier.

Step six (bipolar only): calculate the base current needed (solenoid current divided by current gain (Hfe)). This needs to be 20mA or less for the Arduino.
Choose a base resistor that will pass at least double this current at about 4V (Arduino supply voltage less the Vbe). It's important the drive current is sufficient to drive the transistor into saturation (fully on), hence the factor of two - and remember to use the 'minimum' rating for gain, its the only useful one.

If this current is too big for the Arduino find a transistor with higher gain (such as a Darlington) and redo.

For bipolar transistors you can check the power-handling rating by multiplying the solenoid current by the Von (Vsat) rating at the relevant current, typically about 1V for power transistors, 1.5V for Darlingtons).

For FETs you calculate the power by I-squared-R where R is the on-resistance of the FET.

Remember the FET MUST be 5V logic level compatible, ie it must be switched hard on at 5V gate voltage and fully off at 0V. Many power FETs are 10--15V, not 5V.

The solenoid will be used to push a physical lever

The problem with a solenoid is that they come in with a big thump and they do not normally move very far (called the throw of the solenoid). Depending on how much you want the lever to move you might be better off using a geared motor and lead screw arrangement. You are best trying to work out the mechanical arrangement first as what ever the solution electrically you will always be able to drive it one way or the other.