Electronic – Switching relay with NPN BJT

bjtnpnrelay

I am trying to switch a SPST-NO relay that is rated to handle up to 227VAC. The coil is powered by 5V, has a 100 Ohm coil resistance, and its contacts are rated for 16A max.

I would be using the GPIO pin to power the base of the transistor, which is 3.3v and the 5Vout to power the relay coil.

To make your life easier I will list the relevant data from the 2n3904's datasheet:

Ic(max) = 200mA
Vce(sat) = .2v with 50mA Ic & 5mA Ib
Vbe(sat) = .65-.95v with 50mA Ic & 5mA Ib
hFE = 60 with 50mA Ic & 1v Vce

Relay can be found here:
http://www.newark.com/panasonic-electric-works/adj23005/relay-spst-no-277vac-16a/dp/12N3389

I have the base resistor at 520 Ohms:
R = V / I
= 3.3v – .7v / 5mA
= 2.6v / 5mA
= 520 Ohms

The Ic is found by multiplying the current gain(hFE) by Ib. The test case for Vbe(sat) shows Ib should be 5mA:

Ic = hFE * Ib
= 60 * 5mA
= 300mA

The 2n3904 can only handle 200mA max. I need Ic to be at 50mA according to the datasheet if I want to saturate the base. I would need a resistor to retard the current a whole 250mA.

Am I missing anything? Does this all look good?? Meaning will it work? Please explain anything I am missing conceptually or anything at all I would very much appreciate it!

EDIT: I have researched this topic as best as I could and these are just concepts and question I need help wrapping my head around.Ultimately I would like to be able to do this with out the help of this forum/group and move to mosfets next.

circuit design

Best Answer

Tony's already provided an approach for you to follow. I'd like to suggest another. I'll return to a short discussion about your question, though, later. You write:

I am trying to switch a SPST-NO relay that is rated to handle up to 227VAC. The coil is powered by 5V, has a 100 Ohm coil resistance, and its contacts are rated for 16A max.

I would have wanted to also consider the use of a mains-powered relay and the use of a MOC30x3 device (MOC3063 if you want zero-crossing behavior or a MOC3023, if not.) These guarantee operation when provided with at least \$5\:\textrm{mA}\$.

schematic

simulate this circuit – Schematic created using CircuitLab

This provides opto-isolation, requires a driving current that is routinely available in typical I/O pins from a microcontroller, and powers the relay directly from the mains supply instead of your DC supply rail. And since the relay is AC mains powered and isolated from your DC rail, a simple connection without snubbers works well enough. Just to add still one more useful point, it can be driven directly from your \$3.3\:\textrm{V}\$ I/O pin and there's no particular need for a separate \$5\:\textrm{V}\$ rail.

An OMRON G2R provides some mains powered options and might be such a relay choice.


However, if you must use a separate \$5\:\textrm{V}\$ rail and a compatible relay, then you should operate the switching BJT in saturated mode (active, saturated.)

An early thing to consider is the size of the BJT. In this case, you need a collector current of \$I_C=\frac{5\:\textrm{V}}{100\:\Omega}=50\:\textrm{mA}\$. A saturated BJT will have a \$V_{CE}\approx 200\:\textrm{mV}\$. So that means \$200\:\textrm{mV}\cdot 50\:\textrm{mA}\approx 10\:\textrm{mW}\$. But there's more. The base current isn't accounted for, yet. This will be roughly 10% of the collector current (over-driving the BJT is how you get it into saturation), or about \$5\:\textrm{mA}\$. This will probably require about \$V_{BE}\approx 700\:\textrm{mV}\$. So, another \$700\:\textrm{mV}\cdot 5\:\textrm{mA}\approx 4\:\textrm{mW}\$, for a total of \$14\:\textrm{mW}\$. This is easily within the capability of almost any package, so a small signal BJT like the one you picked out will work just fine.

Note here, by now, that you don't need a base current more than about \$5\:\textrm{mA}\$. So, your base resistor needs to be only about \$\frac{3.3\:\textrm{V}-0.7\:\textrm{V}}{5\:\textrm{mA}}= 520\:\Omega\$. Because this is based on an over-driven 10% figure and because you can rely on the fact that small signal BJTs will saturate well before reaching that figure, it's just fine to relax the base resistor to the next standard value above that figure, or \$560\:\Omega\$. (Probably would work fine with a \$1\:\textrm{k}\Omega\$, but whose counting?)

Tony's suggested circuit with the diode is just fine, by the way, and you should include something like that included diode in order to allow the relay coil a method to de-energize itself when turned off. The time required to de-energize will depend upon the voltage developed across the relay coil, however. And a simple diode presents only a small voltage across the coil, so the time will be longer than it might otherwise be. If time matters to you for reasons you didn't mention, you could consider the idea of including a series zener, as well, in order to jack up the de-energizing voltage and thereby reduce the required time for that phase of operation.


Note that both the AC-powered relay and also the DC-powered option require about \$5\:\textrm{mA}\$ from your I/O pin. The AC-powered method is just an alternative approach to consider and it may expand your options (if not this time then perhaps another time and another place.)