Relay circuit design - Page 1
Forum section: electronics / beginners

author: Handull
author_rank: Newbie
timestamp: July 26, 2016, 08:11:42 pm
content: Hi all,I have a basic 5V relay that I want to control with a 5V digital logic line. I learned that I should put a diode backwards across the coil of the relay and I understand why. I've also seen a lot of people putting a transistor after the relay and controlling the transistor with digital logic, rather than just driving the relay directly. What are the reasons for using a transistor along with the relay? I've attached a drawing of the two circuits I'm asking about. One obvious benefit of using a transistor is that your logic voltage doesn't have to match the relay voltage, so you could use 3.3V logic with a 12V relay. Is using a transistor going to have faster switching or something? Thanks!-Anthony

author: Signal32
author_rank: Frequent Contributor
timestamp: July 26, 2016, 08:15:36 pm
content: The biggest reason for doing this is that most micro's/logic pins don't have the capability to supply enough current to turn on the relay.As for speed, it would actually be slower when using a transistor, but it would be a few nanosecond slower which doesn't really matter when the relay takes 1,000,000 times more to actuate.

author: boffin
author_rank: Unknown
timestamp: July 26, 2016, 08:31:21 pm
content: I'd use a FET rather than a regular transistor. Something like the 2N7000 would work perfectly (still want the reverse diode), and you wont need a currently limiting resistor.If you do it with a regular transistor, you'll need to limit the base current with a 22k-ish resistor in series with the base for a 2N3904/2N2222/BC107

author: MosherIV
author_rank: Super Contributor
timestamp: July 26, 2016, 09:15:36 pm
content: HiThe drawing of the relay being driven directly by the micro GPIO is likely to fail. As you said, you understand the reason for the diode, well as it has been drawn the back emf will likely blow the GPIO port.The better way to do it is to put the relay from power rail into the GPIO port and the the diode will direct the back emf into the supply rail. The logic for driving the relay must be inverted.The power supply need to have a diode to protect against overvolthttp://www.learnabout-electronics.org/PSU/images/78xx-protection-diode.jpg

author: danadak
author_rank: Super Contributor
timestamp: July 27, 2016, 12:24:39 am
content: Wheather a MOSFET or Bipolar add a R from Gate/Base to ground, calculate itsvalue so that any leakage when pin is in tristate will not reach threshold of BEjunction of Bipolar or Vth for the MOSFET.When you pick diode use a fast power diode to limit max emf circuit experiences.Use a scope to confirm you are getting good results in suppression of transientfor the relay you choose.Regards, Dana.

author: Seekonk
author_rank: Super Contributor
timestamp: July 27, 2016, 01:14:55 am
content: Whats wrong with a transistor, but use 1K resistor for the drive. I've never used a 2N7000 FET. From what I've seen around here, I have the same fondness for them as I do the 555. People seem to have a lot of issues with them, they don't seem robust. Any common 1A diode will work. Most diodes turn on fast, just some are slow to turn off. Plenty fast for any relay circuit. Use a 12V relay if possible. Driving relays from a 5V supply is always asking for trouble. When you get a little better, drive the relays with PWM to save current. It can always be dropped in half.

author: MarkF
author_rank: Super Contributor
timestamp: July 27, 2016, 01:27:43 am
content: If you have a number relays you want to drive, a ULN2003 is designed just for the task and has the diode built-in.

author: danadak
author_rank: Super Contributor
timestamp: July 27, 2016, 11:18:50 am
content: Here is a good discussion and testing of low cost power diodes -http://www.cliftonlaboratories.com/diode_turn-on_time.htmAs Seekonk pointed out the Turn on time of these cheap power diodes pretty good. Butif the diode is in Trr when you try to turn it on therein lies a potential problem. But mostrelay driving has exhausted Trr before its asked to conduct, so issue should be moot.Regards, Dana.

author: Jeroen3
author_rank: Super Contributor
timestamp: July 27, 2016, 11:29:12 am
content: Circuit 1 is missing two resistors.R1. gate/base resistor.R2. gate/base pulldown to not half-enable the relay on tri-state output.

author: madires
author_rank: Super Contributor
timestamp: July 27, 2016, 11:57:04 am
content: Quote from: Seekonk on July 27, 2016, 01:14:55 amIs PWMing a relay a good idea? What about EMI? Wouldn't it be better to switch the relay to another power rail with a lower voltage?

author: danadak
author_rank: Super Contributor
timestamp: July 27, 2016, 04:18:32 pm
content: Use a latching relay and pulse it to switch back and forth between open and closed.No PWM needed, and optimal power consumption ( if switching is basic on off switching),only draws power during applied pulse.Regards, Dana.

author: tatus1969
author_rank: Super Contributor
timestamp: July 27, 2016, 11:46:24 pm
content: there is another - yet more subtle - reason to not directly use a GPIO port to drive an inductive load like a relay. When the relay is switched off, the free-wheeling diode conducts. During this situation, you have roughly -0.7V at the GPIO. This negative voltage may cause a latchup in your microcontroller, which at least inhibits normal operation until the next power cycle, and even may thermally destroy it. It largely depends on the type of microcontroller, some have specified latchup immunity and are robust against this failure.

author: danadak
author_rank: Super Contributor
timestamp: July 28, 2016, 02:11:09 am
content: tatus1969 brings up a very good point. Across the profession we have been protectingI/O pins with Si diodes, but that raises the question, which diode has the lower threshold,the internal diode we are trying to prevent from drawing current, or the external one weare using to protect the internal one ?The sure footed solution is to use schottky diodes, or SiC, as their Vth is inherently lower (pickingthe correct part of course).The latchup mechanism, parasitic SCR, is a little more complicated as not only is there a Vthto trigger but its sensitive to dV/dT effects. Most modern controllers now state latchup conditionsand the resulting current when latchup occurs. In the past latchup generally was destructive,resulting in blowing open internal power rail bond wires, or melting silicon in hotspot areas.Recently some vendors state that latchup, once power is removed, can be recovered from.Even if latchup does not occur charge injection into pins can result in erratic behavior, as thecharge release into the substrate has no predetermined sink for it, so random logic can be affected.So consult datasheet.Regards, Dana.