12V Output

I work for a research lab that is working on a project that needs some control. We have traditionally used National Instruments LabView systems as that is what has always been used and its got a reputation as "easy" since its not "real" programming. Anyway, were using 1500+ dollars of electronics to essentially flip switches.

My back ground is in process automation, and mechanical engineering. I am not afraid of learning a little code, and I know my basics with electronics and such. Yea, I am one of those people that knows just enough to be dangerous... Anyway after much heckling over the purchase of yet another 1K+ NI purchase my punishment is the task of coming up with something cheaper. (I am so glad my PI has not learned stuff like this isn't punishment.)

Now my question: I need to drive a combination of 12V and 5V valves (apply 12V=open, 0V=closed). I can drive the 5V ones straight from the Arduino board, but I was wondering how you all would recommend an easy way to drive 12V outputs. Is there a chip that essentially has a bunch of relays that is compact?

Thanks, Crash.

you shouldnt need a relay, a simple transistor switching circuit should suffice.

chip output is an output pin on the arduino, your Vs is 12V and your V0 is ground.

Load is your valve. Resistor values are decided on the specs of the valve and transistor. You will need a protection diode.

Also, I would wire the 5V valve the same way. Wiring an inductive load straight to the arduino isn't a good idea.

Here is the site I got the pic from: http://www.kpsec.freeuk.com/trancirc.htm

it has instructions on calculating the resistor values

Well, the first big question is: are you going to be directly controlling the power to the valves? Or just supplying a “logic level” of 5V or 12V at a few microAmp or milliAmps of current?

If you’re supplying the valve power, do you have the option of wiring them up the way darudude suggested? Or are they already wired so you’re forced to supply the positive voltage? It’s usually easier and cheaper to switch the ground side. Plus, you have the advantage that you can use the same circuit for both types of valves.


Thanks for that graphic, I had actually just come across a very similar on someones flicker page. This is my first foray into microcontrollers, so I am learning a lot.

I have the valves loose, so I can wire them however I want. I really like the idea of ground switching, I had not thought of that. I am not supplying logic level power, I am powering the valves. I don't know what that is off the top of my head, but its all easily sub 1/4 amp.

What does the protection diode do/protect against?


Edit: Ran, that is an awesome link, I am a little fuzzy on transistors, so that's going to help.

since a solenoid valve is a magnetic load, when it is turned off there is a sudden voltage spike. the protection diode protects the arduino from that.

there is more info on the link i submitted in my first post

I had actually just come across a very similar on someones flicker page.

My one, maybe?


You’ll need to know how much current the solenoid valves draw, so that you can choose a large enough transistor and power supply. The maximum that you can draw from a Arduino pin directly is 40mA, which is unlikely to be sufficient.

Yup, that was yours!

Our 5 volt valves are ultra small and may very well be under 40mA, but I think it would be easier to use this one method across all.

Is there a chip that does this all on board for a couple of lines on I/O? I could bread board one or two of these, but when I am using 5-10, it would be nice to have a chip that handles a couple lines in a small footprint.

Also if your reading this and your new, this is an awesome link to check your math on your circuit analysis, I know it, but its good to be able to check it before the blue smoke:

Edit: With the above example (looking for a chip that does all that) how does one locate products like that without simply spending so much time in the field that you just know.

There are serial-to-parallel chips with open-collector or open-drain outputs that can drive from a few hundred mA up to a couple of A. Some use a standard interface (like SPI or I2C), some are similar to normal TTL or CMOS logic shift registers. SOme have protection diodes built-in, some don't.

The TPIC2603 is a nice chip for the SPI bus. The TPIC6C595 is one that others have recommended: it's similar to the 74HC595 shift register, and doesn't use a defined "bus". There are probably some for the I2C bus, too, but I don't know of any, offhand. But, even if there isn't, for $3-4 you can use a standard 8-bit I/O expander like the PCF8574, and connect it to a standard multi-pin power driver like the ULN2803, to drive 8 relays/valves/motors per pair of chips with just 2 Arduino wires.

The I2C bus is nicer than SPI in some respects: it uses fewer wires, especially if you're going to be hooking up multiple peripherals. It does steal 2 analog inputs on the Arduino if you use the on-chip hardware interface. It tends to be a little slower, witha little more CPU overhead, than SPI, but you're not going to be doing the sort of high-volume I/O where that would matter. Also, the most popular Ethernet interface for the Arduino uses SPI, and I've seen a couple of complaints from people (possibly later resolved) about trying to get it to play nice with other SPI peripherals.


Okay guys, this is a lot of good info. I have been confused by the communication between chip stuff, I bought an LCD that uses that so I could play with it and hopefully it makes more sense when I see it work.

So as to my question about a chip that does the transistor switching circuit, I have not had luck googling for information. I am sure its out there, I am just not sure what to search for. Lets say that I want to find a chip that has 4 or more “lines” (is that the right word) of switches. Essentially what darudude posted, but four on a single chip that is controlled by I2C bus. How does someone that is not familiar with whats out there find something? What are the proper names for this type of switch I could google and find more info?

Thanks again for all your great insights and help!

I am not sure why you want to get involved with I2C to drive the valves as you could use the output pins directly. The I2C device would be a port expander, this just gives you extra logic outputs. Like the MCP23016, you get 16 input / outputs with that one.

Then to actually drive the valves you need a driver (the clue is in the name) chip or as mentioned before some extra transistors or FETs. Have a look at one of my links, valves are very much like motors as far as driving is concerned. http://www.thebox.myzen.co.uk/Workshop/Motors_1.html also see Motors 2 on the same site for driver ICs

There's a handy 8-bit driver chip, the ULN2803. It has eight darlington driver outputs that you can use to drive things like solenoids and relays. The inputs are TTL-compatible digial pins. You may also find the ULN2003 which is a 7-bit equivalent.

I had read about the darlington pair. Its simply a more sensitive version of the first solution (the single transistor).

What would be the benefit of using a darlington pair in an application like this (Arduino) vs, the single transistor design? It appears to just add complexity when the Arduino is capable of driving the single transistor system. (I am not questioning you, I am trying to understand why/if one is better than the other)

Also, is this essentially a MOSFET? I keep coming across MOSFET's in my googling and they seem very similar. They even have optically isolated MOSFET's which, if I understand it correctly, help to isolate the two circuits, and allow you to break away from sharing a common ground.

What would be the benefit of using a darlington pair in an application like this?

A darlington pair will need less base current than a single transistor, due to the higher current gain. In the case of the ULN2803, the designer used darlington pairs so that the chip could drive the full output current while still requiring only a small current from the logic chip that drives it. It's more complicated when built with discrete transistors, but when there's a ready-made chip, it's probably simpler.

Also, is this essentially a MOSFET?

No, a MOSFET is a different kind of transistor altogether. They are fundamentally voltage-driven, whereas a bipolar transistor is current-driven. That is, a certain base current flows, and that controls a collector current (via the gain of the transistor). A MOSFET needs a few volts (about 8V usually) to fully switch "on", and then it behaves like a very low value resistor (a few milliOhms in some cases), whereas a bipolar transistor will behave like a diode (and hence have a small forward voltage drop).

Optical isolation is commonly used when you need to break the ground connection. Usually done with a LED that shines on a photodiode (or phototransistor) inside an opaque case.

Hope that makes sense!

the main benifit of a mosfet is it's high input impedence. This allows for the circuit that is switching the mosfet to not be influensed by the mosfet's current dynamics (unlike a bjt, which is always affected by current dynamics).

A mosfet is kind of like an isolator as its switching circuit is not affected by the mosfet circuit. However, as far as I know, the grounds have to be the same for this to work right.

The benifit of the optical isolator is that it allows you to have seperate grounds and still be able to switch without hiccups.

the main benifit of a mosfet is it's high input impedence

Well not in interfacing with physical computing. The main benefit of a MOSFET is its low on resistance. This means that very little power is dissipated in the switching device allowing you to switch more current per watt of heat wasted.

The main reason people keep bringing up Darlingtons and MOSFETs is that it's very likely that you're going to be surprised when you get out the specs on those valves, and find that they use a lot more current than you think they do.

Another suprise to watch out for: multi-driver chips like the ULN2803 can be very handy, but read the fine print in the datasheet. Even though each driver can handle x-hundred mA, if you have more than a few of them driving the maximum load at once, they can generate enough heat to fry the chip in a matter of seconds. If you use them, plan your connections so that "mutually-exclusive" valves tend to be controlled by the same chip to minimize the number that each chip is driving at any given time.


I think darudude’s schematic in the first reply will do well for you. You can use common 2n2222 transistors and the (Rb) resistors would be around 250 ohms (220 ohms is a common value), regardless of valve solenoid voltage. This would allow roughly 20mA to hit the base of the transistor (Ib) and should give you about 800-1000mA of available drive current (Ic) per valve solenoid (RL). Definitely use the protection diodes too.

If for some reason, the valves were opening weakly with these values, you can reduce the Rb resistor values a little to allow the transistor to saturate better and provide more voltage across the valve solenoid. Just don’t pull more than 40mA from any pin on the Arduino. And try to limit the number of pins pulling near the max current. There is a cumulative limit, but I don’t remember it off the top of my head.