# PIC to drive Relay

Discussion in 'General Electronics Chat' started by Dalaran, Mar 18, 2011.

1. ### Dalaran Thread Starter Senior Member

Dec 3, 2009
168
0
I'm working on a circuit which is to use a PIC output pin to toggle a relay. The 5VDC relay I am using has ~70ohm coil resistance to be driven from a PIC16F886. It seems that the uC cannot supply enough current to toggle the relay.

I'm assuming my problem could be accomplished by placing a FET or BJT in between the two, only I'm not exactly sure how to do that. Can anyone recommend a part number and circuitry to do this?

Thanks.

2. ### Jaguarjoe Active Member

Apr 7, 2010
770
91
Google "transistor switch" and >5x10^6 results pop up.

3. ### SgtWookie Expert

Jul 17, 2007
22,202
1,792
Here is a suitable driver using a single resistor, 2N2222 transistor as a saturated switch, and a diode across the relays' coil to suppress the reverse-EMF spike when the transistor is turned off:

To optimize R1's resistance, first calculate the coil current:
I = 5v/70 Ohms ~= 71.4mA

So, the required collector current (Ic) is 71.4mA.
When used as a saturated switch, the base current needs to be 1/10 that of the desired collector current.
R1 = (Vin - Vbe) / (Ic / 10)
where:
Vin = the high voltage supplied by your PIC I/O pin; nominally 5v.
Vbe = the voltage from the base to the emitter when the transistor is ON, nominally 0.7v for light-to-moderate loads.
Ic = the desired collector current.

Substituting and simplifying:
R1 = (5v - 0.7v) / (Ic / 10)
R1 = 4.3v / 7.14mA
R1 = 614 Ohms.
Looking at a table of standard resistances:
http://www.logwell.com/tech/components/resistor_values.html
you'll see in the green E24 columns that 620 Ohms is the closest standard value, and is ~104% of the desired 614 Ohms. This should work OK.

Don't go much higher than that, or the transistor may come out of saturation. You can use a lower value resistor as long as you don't stress the I/O pin. 220 Ohms is about the lowest you can go for a base transistor when driven by a PIC powered by 5v Vdd, or you'll exceed the 20mA limit. Better to stay lower than that.

File size:
6.7 KB
Views:
155
4. ### Dalaran Thread Starter Senior Member

Dec 3, 2009
168
0
Thank you very much for your detailed response SgtWookie.

Is the diode size critical? ie, would a 1N4001 be suitable?

I have JE181 BJT's on hand... I assume this would be a suitable substitute as it doesn't seem to matter too much on the transistor characteristics.

Thanks again!

5. ### SgtWookie Expert

Jul 17, 2007
22,202
1,792
The MJE181 is an NPN power transistor rated for up to 3A collector current and Vce of up to 60v. It will work, although it's maximum overkill.

The diode isn't critical; just as long as it has a reverse breakdown voltage greater than 5v. You could even use a 1N914 or 1N4148 switching diode, as the coil current is pretty low.

6. ### Dalaran Thread Starter Senior Member

Dec 3, 2009
168
0
Thanks again. Everything seems to be working just fine!

Just a follow-up question I guess. I was under the impression that say a n-channel MOSFET would be a better solution? But around the net all I see is the use of BJT's for this type of configuration.

With a n-channel could the 5V from the PIC not be used as the Vgs and open up the source-drain pathway? Is there a reason why people generally use BJTs in this set-up? Just wondering! Thanks!

7. ### SgtWookie Expert

Jul 17, 2007
22,202
1,792
Yes, you could use a logic-level MOSFET.

A 2N7000 is a popular N-ch MOSFET in a TO92 package. It would work OK for this. It's rated for up to 200mA drain current, but you should really stick below that. Derating transistors/MOSFETs by 50% collector or drain current is a good idea for longer life.

An IRLD024 is a nifty N-ch MOSFET in a 4-pin DIP package that can sink up to a couple of amperes. Good for breadboarding, too.

Dalaran likes this.