Relay switching circuit...sanity check - Page 1
Forum section: electronics / beginners

author: ampdoctor
author_rank: Frequent Contributor
timestamp: December 02, 2014, 06:57:44 pm
content: Below I've attached a schematic of a very simple relay driver circuit. Problem is that it seems almost too simple. While I haven't physically built it, the thing simulates just fine and with very few modifications should mate up with micro's, latches, etc. Anything that produces logic high or low.It seems simple, low cost, robust and easily modifiable to work with different loads, switching methods, or rail voltages. So after all that wordiness, the question comes down to...where is the brain fart, and what am I missing? It just can't be this simple.

author: Zero999
author_rank: Super Contributor
timestamp: December 02, 2014, 09:00:02 pm
content: It looks fine to me. The only thing which could be a problem is Q1 may need more base current, try omitting R1.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: December 02, 2014, 09:16:08 pm
content: If you omit R1 you will be shorting Vcc to ground through the switch or logic low of any driving circuit

author: jlmoon
author_rank: Unknown
timestamp: December 02, 2014, 09:30:55 pm
content: Remove R2 and make R1 ... 2200 ohms and you should be good. Even 1k ohms as R1 and R3 would work.

author: tggzzz
author_rank: Super Contributor
timestamp: December 02, 2014, 09:33:49 pm
content: Quote from: ampdoctor on December 02, 2014, 06:57:44 pmWhy don't you simulate it with an inductor? Simulating only the relay's resistance is rather missing the point!

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: December 02, 2014, 10:04:33 pm
content: To guarantee full saturation of the transistor, use the Ib = 1/10 of Ic rule. Using the Min hfe from the specs for the transistor being used.Remember if Ib is high for your first transistor, that might exceed any logic/micro output currents, so you might need a Darlington on the first stage.Or you could just use mosfetsWhat is the load current of your relays

author: ampdoctor
author_rank: Frequent Contributor
timestamp: December 02, 2014, 11:38:44 pm
content: Quote from: tggzzz on December 02, 2014, 09:33:49 pmUsing a resistive equivalent is just being lazy for the sake of proof of concept simulation. I also don't want to lock myself into just using relays. At some point I may want to use LDR's or something else.I'm trying to come up with a very simple generic switching circuit that can be substituted into a number of different applications.Quote from: Mr Smiley on December 02, 2014, 10:04:33 pmrelay 1(R6) is going to draw 200mA and the other(R7) draws 100mA. Component values aren't exactly optimized but they're close enough as a general solution. As I mentioned higher up in the comment, I'd like to be able to use this circuit under any number of different conditions with the fewest topological changes as I can get away with.

author: tggzzz
author_rank: Super Contributor
timestamp: December 03, 2014, 12:39:13 am
content: Quote from: ampdoctor on December 02, 2014, 11:38:44 pmSo lazy that you haven't actually proved anything about using a relay coil - only about using a resistor. Hmm.

author: ampdoctor
author_rank: Frequent Contributor
timestamp: December 03, 2014, 02:25:11 am
content: Who gives a damn? I change relays within a series or manufacturers and the data becomes useless because the inductances and/or coil resistances are going to vary substantially. I'm not designing launch vehicles or life support equipment here. It's just a simple switching circuit. All I need is a lumped element model to approximate the load current to see if the transistors will respond roughly as expected. So calm down and don't get your panties in a knot. Unless you can give me a damn good reason to accurately model the coil, your comment makes you sound like a petty internet troll looking to pick a fight while not actually contributing anything of value to the discussion.

author: tggzzz
author_rank: Super Contributor
timestamp: December 03, 2014, 09:20:41 am
content: Quote from: ampdoctor on December 03, 2014, 02:25:11 amClearly you care enough to spend time doing the simulation and then asking us to spend our time critiquing it.QuoteIn which case what do you expect to learn from a single simulation, when you could more easily get a better understanding from thesimplekey equations that define the operation across a whole range of conditions? That suspicion is confirmed by your next statement...QuotePot, kettle, blackQuoteDon't waste our time asking for answers you aren't prepared to listen to, nor information that you don't actually want!

author: Zero999
author_rank: Super Contributor
timestamp: December 03, 2014, 11:44:46 am
content: Quote from: jlmoon on December 02, 2014, 09:30:55 pmSorry, that's what I meant to say.Quote from: Mr Smiley on December 02, 2014, 10:04:33 pmIt doesn't need to be in full saturation to work, a voltage drop of around 1V or so shouldn't cause any problem, so a forced beta of 100 should be fine.

author: LukeW
author_rank: Frequent Contributor
timestamp: December 03, 2014, 12:03:00 pm
content: Modern LEDs typically don't need current that high to have a good light output. I typically use 1k for LED series resistors in 3-5V systems.

author: extide
author_rank: Regular Contributor
timestamp: December 03, 2014, 08:52:43 pm
content: 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!

author: max_torque
author_rank: Super Contributor
timestamp: December 03, 2014, 11:48:49 pm
content: 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.......

author: ampdoctor
author_rank: Frequent Contributor
timestamp: December 04, 2014, 02:28:47 am
content: Quote from: extide on December 03, 2014, 08:52:43 pmSure, 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.Quote from: max_torque on December 03, 2014, 11:48:49 pmGenerally 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.

author: Zero999
author_rank: Super Contributor
timestamp: December 04, 2014, 11:15:26 am
content: QuoteProviding the base current is high enough, that shouldn't be a problem. Just ensure the base current is more than high enough to give sufficient collector current at a low collector-emitter voltage.QuoteThe ULN2803 should do but just for two channels, it's not really worth it.

author: Richard Crowley
author_rank: Super Contributor
timestamp: December 04, 2014, 12:37:23 pm
content: Does the 1K value of R1 represent some limit to the drive power available?The reason for the question is because in some cases you may be running into limits of switching current vs. drive current vs. the hfe(current gain) of the switching transistors. That is why people are asking questions about the resistance value of R1 and R2/R3. You can't expect to pick the value of R2/R3 without taking into account the gain of the particular transistor, and the current requirement of the load (the relay coil + LED) In cases of limited drive current and heavy load current, you may need something with much more current gain such as a Darlington pair or MOSFETWhat kind of switch is S1? Can it be a SPDT (so that you don't need to pull against R1)? Does it require de-bouncing?I don't see much point in simulating the inductance of the relay coils. Except that you can simply assume that they have some significant inductance (unless they are solid-state relays, etc.) So providing a reverse diode across the relay coil (to absorb the current generated by the collapsing magnetic field) seems like a hard requirement to prevent early failure of the switching transistors.Remember that most relay switches are available in "form-C" (double-throw) with varying number of poles. So alternately driving two relays may be overkill in many applications where you could just take advantage of the switch contacts on a single relay.