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
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.
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
Hi
The 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 overvolt
http://www.learnabout-electronics.org/PSU/images/78xx-protection-diode.jpg
Wheather a MOSFET or Bipolar add a R from Gate/Base to ground, calculate its
value so that any leakage when pin is in tristate will not reach threshold of BE
junction 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 transient
for the relay you choose.
Regards, Dana.
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.
If you have a number relays you want to drive, a ULN2003 is designed just for the task and has the diode built-in.
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. But
if the diode is in Trr when you try to turn it on therein lies a potential problem. But most
relay driving has exhausted Trr before its asked to conduct, so issue should be moot.
Regards, Dana.
Circuit 1 is missing two resistors.
R1. gate/base resistor.
R2. gate/base pulldown to not half-enable the relay on tri-state output.
When you get a little better, drive the relays with PWM to save current. It can always be dropped in half.
Is 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?
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.
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.
tatus1969 brings up a very good point. Across the profession we have been protecting
I/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 we
are using to protect the internal one ?
The sure footed solution is to use schottky diodes, or SiC, as their Vth is inherently lower (picking
the correct part of course).
The latchup mechanism, parasitic SCR, is a little more complicated as not only is there a Vth
to trigger but its sensitive to dV/dT effects. Most modern controllers now state latchup conditions
and 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 the
charge release into the substrate has no predetermined sink for it, so random logic can be affected.
So consult datasheet.
Regards, Dana.