What is the purpose of the transistors in this circuit? Why not just switch the relays directly with the switch? Can someone explain how this circuit works?
Do the transistors make it so you see less switching current at the switch? How exactly does that work?
Thanks!
Sure, you could switch the relays directly with say a mechanical SPDT switch to ground and it would work just fine and be a lot simpler, IF that's the only way you're changing states. Also mechanical switches are statistically more prone to failure. However, let's say you need the relays activated through a momentary switch(higher reliability), or you're getting a logic signal from some other source to turn on and off some pumps or whatever you're doing, then things get a little more tricky. That's why I drew it up using a rather generic switch...for ease of illustration and proof of concept.
In terms of general circuit operation, when the switch is open or logic high, the junction of R1 and R2 sees roughly 5 volts and the amount of current flowing through the base of Q1 is set by the value of R2.
When Ib(Q1) is high enough to turn the transistor on you see a current flow from collector to emitter of Ic = hfe(or beta)*Ib. This looks a lot like a short to the relay and its turned on. In this state the voltage seen at the collector of Q1 is low, around 300mV give or take and is lower than the pn diode drop across the base emitter junction of Q2 which keeps that transistor turned off. In other words, the be junction is reverse biased, therefore no significant current flows from collector to emitter in Q2 and relay 2 is turned off because it looks like an open.
Now, when the switch is closed or low, Q1 is turned off and no current flows from its collector to emitter so the collector voltage is close to the rail voltage. This is high enough to get a small amount of current flowing though the base of Q2 and is calculated the same way we did for Q1. Now that we have base current flowing Q2 turns on and current flows across its collector emitter junction and relay 2 activates. End result is that we've got one switch or signal toggling the state of two transistors.
R4 and R5 are just current limiting resistors for the LED's and are calculated using Ohm's Law and the max allowable current of whatever diode you decide to use.
Having said that, the circuit is NOT perfect. The one primary issue is that Q1 and Q2 are beta dependent biased. This means that if beta drifts over time or through junction temperature changes the circuit's operating points will change so you need to allow for that in the design process or use independent beta biasing. You could do that by creating a voltage divider by putting R2 to ground and attaching the base to the junction. Then calculate the base current using Ohm's Law. You can do something similar with R3 and Q2.
And yes, I left out a lot of details for the sake of clarity to conceptually understand the basic operation of the circuit.
TBH, in 2014, i'm not sure why anyone bothers to "roll their own" drivers, unless you are making 10,000 units and trying to save every single last $$. Just use one of the off the shelf relay/solenoid driver ICs, that can if required drive multiple channels, and also often have diagnostic / safety functions / limitations etc. For home/hobby use, i've found that soldering a single IC into place is "cheaper" than pretty much any discrete solution due to the faster assembly, and less chance of mistakes creeping in etc.......
Generally I can agree with this. However, in this particular case these relays will be operated continuously and I'd be right at the margin of what I can get away with using something like a uln2x03 or similar chip. If you know of a chip that can sink 300mA/channel all day long in an enclosure with no airflow then I'm all ears brother! Can I get away with it using a ULN2803? Probably, but I don't like to push my luck and I like lots of design margin. Also, when I do custom work for people I lose track of the chain of custody and have no clue who will service these things or what resources they have available so I would prefer to use jelly bean parts and rather generic switching transistors, diodes, etc that Joe Schmoe can get hold of in the middle of BFE nowhere. So it's less of an engineering decision and more of a customer service decision. Saves me headaches down the road.