1
\$\begingroup\$

I need to control about 10-ish 5 V relays from an ESP32 DevKit, each on its own GPIO. Normally only one or two will be active at the same time.

Most questions I see asked here are about pre-made relay boards; I want to control the relays directly as I need DPDT relays (most boards are SPST relays and big for nothing).

My transistor notions are pretty far in my head, I made up a circuit using parts I had laying around, it works, but I just want to make sure it's going to be OK in the long run and I'm not overlooking anything.

Relays are HK19F Power Relay (5 V coils). They are going to be switching 12 VDC loads.

Does this circuit make sense?

Circuit

\$\endgroup\$
3
  • \$\begingroup\$ R1 will need to be smaller and there will be a question about whether or not the GPIO pin involved will happily support the needed BJT base current. The datasheet specifies four different coil resistances for the 5 V relay. (I guess they make a LOT of versions -- some with more and some with less coil power.) Do you know which specific version you have in hand? \$\endgroup\$ Mar 11 at 3:58
  • \$\begingroup\$ Only thing I know it that's its written HK19F-DC5V-SHG on the relay body, there's no more info except the rated load of the contacts. \$\endgroup\$
    – Answer_1
    Mar 11 at 14:43
  • \$\begingroup\$ That's perfect. You can get what's needed from that number! \$\endgroup\$ Mar 11 at 18:33

3 Answers 3

1
\$\begingroup\$

Thanks for providing more information about the relay. It's now understood the complete part number is HK19F-DC5V-SHG. It's not always necessary to have such a complete number like this. But in this case the company appears to make four different sub-versions of their \$5\:\text{V}\$ version. I don't see that very often. But there it was.

Here is the HK19F-DC5V-SHG datasheet. You can see that they specify four different versions at \$5\:\text{V}\$.

enter image description here

So you look at the ordering information to clarify, given your fuller part number:

enter image description here

This means you have the \$200\:\text{mW}\$ version, which is \$125 \:\Omega\$, nominal. The equilibrium full current will then be \$\sqrt{\frac{200\:\text{mW}}{125 \:\Omega}}=40\:\text{mA}=\frac{5\:\text{V}}{125 \:\Omega}\$.

Now you know the maximum collector current for the BJT. The rule of thumb is to specify \$\frac1{10}\$th of that for the base current. But that rule isn't always good. In the case of power transistors like the 2N3055, twice as much or more may be required. But you won't need one of those, here.

Technically, the BJT datasheet should always be consulted. But in this case, with only \$40\:\text{mA}\$ that can be handled well by most general purpose small signal BJTs used for switching purposes, it's not necessary. There's a different question that is more important.

What's the I/O pin current compliance?

I don't have a datasheet to look at for your device. You didn't provide a way to directly find it and there are too many to sort through to see if there is a common value available or if they differ so much that nothing can be said. So this will be the uncertainty.

But given the rule of thumb, a base current of \$\frac1{10}\$th of \$40\:\text{mA}\$ or \$4\:\text{mA}\$, I'd say that unless the circumstances are unusual it's likely okay.

At \$40\:\text{mA}\$ for the collector current, the base voltage will likely be in the area of \$700\:\text{mV}+28\:\text{mV}\cdot\ln\left(\frac{40\:\text{mA}}{1\:\text{mA}}\right)\approx 800\:\text{mV}\$. (I didn't add all my thinking here, but I'm allowing for some warmth in the BJT and taking some experience with small signal BJTs into the bargain.)

I'd also expect to see no more than \$100\:\Omega\cdot 4\:\text{mA}=400\:\text{mV}\$ drop at the I/O pin (it will likely be less, but this is a probable worst case.

So the base resistor value should be \$\frac{3.3-400\:\text{mV}-800\:\text{mV}}{4\:\text{mA}}=525 \:\Omega\$. Since I was conservative up to this point (the \$\frac1{10}\$th rule of thumb, the output impedance of the I/O pin, etc), a larger value would be the direction to head. So either \$560\:\Omega\$ or else \$680\:\Omega\$. Both would likely work very well. (Still higher values may also work quite well. But unless you have a reason, such as not having those values handy, then being on the conservative side will allow most any 'junkbox' small signal BJT to be used here.)

\$\endgroup\$
2
  • \$\begingroup\$ From the info I found about the ESP32, the max amps a GPIO can handle is 40mA. \$\endgroup\$
    – Answer_1
    Mar 11 at 20:12
  • \$\begingroup\$ @Answer_1 Then you are in very good shape. There will be no problems. Also, given that fact I'd guess the output impedance is closer to 10 Ohms rather than the 100 Ohms I said would be worst case. This doesn't really alter the resistor value recommendations, though. \$\endgroup\$ Mar 11 at 20:14
2
\$\begingroup\$

It's a good start.

it looks like those relays want 30 to 90mA (depending on which you choose) so you want about 1/10 of that into the transistor base to ensure saturation (which prevents overheating the transistor) reduce R1 to 1K ohms to 330 Ohms.

This leads to less than 1/10 but small transistors typically have stronger gain, you can push the 1/10 rule of thumb out to 1/20 with no worries.

To save space D1 can optionally be a smaller diode like 1N4148 or BAT54.

PN2222 will save you money over the metal cased 2N2222. If space is critical a smaller (surface mount) transistor can be used, I use BC847 here.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for that info, I'll try the 1k instead of the 10k later today and report back. \$\endgroup\$
    – Answer_1
    Mar 11 at 14:58
  • 1
    \$\begingroup\$ Swapped the 10k for a 1k, still working as it should. Left the relay energized for 5 minutes, no sign of anything getting warm. They are gonna be controlling different functions on an 1/10 RC truck rotator heavy wrecker, so they mostly won't be ON for long periods of time. \$\endgroup\$
    – Answer_1
    Mar 11 at 19:36
0
\$\begingroup\$

Yes, this will work very well. You can add a 100k Ohm Resistor from the base of the NPN-transistor to GND.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ It would, except that these relays come in four flavors of coil, nominally using anything from 30 to 90 mA. To operate the BJT as a switch it is a rule of thumb to apply 10% of that as a base current. So 3 to 9 mA. That would require a voltage drop of from 30 V to 90 V across a 10 k resistance. Which really isn't going to happen here. \$\endgroup\$ Mar 11 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.