ESP32 + N2222A for relay trigger. What about power fluctuations?

I've been wondering...

I have a few low-trigger relays that I'm driving with N2222A (GND flows from Collector Emitter to Emitter Collector when Base is triggered High from ESP32). I will be using these relays to power some mains power devices, such as a speaker amp, that I want to make sure never turn off inadvertently. I don't know whether ESP32 might have the tendency to drop a couple of volts for a microsecond(?)

Perhaps there are other components I should add to the circuit to mitigate such risk of a brief power drop; a capacitor, perhaps. I don't need any of my relays to be triggered immediately; I can afford a second or two delay for good measure.

Any advice?

Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

I'm not at the project site at the moment. This is exactly what I've built, 4.7k resistor in series between each GPIO and Base (8 relays, so 8x GPIO and 8x N2222A and 8x 4.7k). I'm using an ESP32 and my relay board is this one.

Edit: Part 2 to the question. What if I use an SX1509 to drive the GPIO instead of the ESP32 directly, with a separate 3V power supply just for the SX1509? Is there still any advantage in accounting for potential voltage drops? And how would the approach be any different?

Do you have eight of these boards, or one 8-channel relay board.
A common 8-channel low-trigger board with opto couplers can be driven directly with a 3.3volt pin.
No transistors needed.
Leo..

I have one that board I linked-to with eight relays on it. I've already built this "relay" part of my project, a couple of months ago, with the transistors (...and the SX1509, actually. It had slipped my mind that I had used the SX1509 to drive the GPIO and not the ESP32 directly). Everything has worked perfectly during my tests and I'm happy to leave the transistors in place even if they're an unnecessary step. I am just wondering, as I finalize my project, whether there could arise the concern of voltage drops if I leave the relays triggered for days at a time.

The ESP is 3V3 output so a driver (your transistor) is necessary.

Long term is not a problem, unless this is powered by battery :wink:


BTW
Your DC pump will need a kickback diode across the coil.

Thank you @LarryD and @Wawa.

Please study relay module diagrams.
The common ones with opto couplers have a 1.2volt opto LED and a 1.8volt indicator LED in series that drop 5volt to the level of a 3.3volt-logic output pin.

The kickback diode is needed though.
Leo..

That means I could invert the GPIO and turn "on" the relay by switching the GPIO from High to Low? ...and just connect the GPIO straight to the relay board?

I find there is still some current flow as the two LEDs do not have a snap ON/OFF action.

Hi,

If you build your project with reliable components and use safe and good quality construction, your project should perform properly.

A reliable power supply will help ensure your projects performance.

Tom... :smiley: :+1: :coffee: :australia:

1 Like

Sure, turn-off voltage of the two LEDs could be 0.8volt and 1.2volt, but that is still below HIGH of a 3.3volt pin. And there is a 1k resistor in series with the LEDs.
Leo..

IMHO, it seems that full ON/OFF switching of devices should be adhered to in digital designs; this isn’t Instructables after all.

If poor habits are not pointed out to new users, they may apply these habits to other situations.

Proper switching design says to have a fully ON or fully OFF driver which the OP has apparently used successfully.

Adding their transistor to the relay is the correct way of designing this control circuit.

If a SMD 3V3 logic MOSFET was available, I would suggest it be used also/instead.


However, if you have successfully done this in the past, then can’t argue with your results.

The schematic shows the relay Vcc fed by 5V, should be no problem for the ESP I/O pin to sink 2mA, the transistor is just inverting the input to HIGH true instead of LOW.

You mention 2mA...

I'm wondering, when the MCU sends a HIGH output to the base of the 2N2222, how many mA might it be drawing?

...I mentioned earlier in the thread that I am powering the SX1509 with a separate 3V supply, but I'd prefer to take power off the 3V3 pin on the ESP32 instead if I could. Given that I have 10 of these 2N2222 switches driving 10 separate relays (and so I am using 10 GPIO on the SX1509 that could be all be high simultaneously) I don't want to overdraw the 3V pin on the ESP32. Might this be a concern? Here is my pinout:

Perhaps someone is experienced enough with ESP32 to glance at my pinout and determine with ease whether I can use the 3V3 pin to power the SX1509 without straining the ESP32.

By the way, I just realized today that I might be sending 5V logic into pins 2 and 15. If so, I'll move the data over to the SX1509 because it's 5V tolerant.

After some research I'm confident that the ESP 3.3V will supply enough current. I connected the SX1509 to the pin.

The I/O expander itself draws virtually no current.
The only current that the 3.3volt VCC pin has to deal with is the base resistor current * 8,
which is (3.3 - 0.65) / 4k7 = 4.5mA, which is not a problem.

Note that you can't draw the coil current for eight relays (8 * 75mA) from the 5volt pin.
Leo..

A capacitor does seems like a good idea.

As I see you already have the driver transistor on the relay pcb, why extra bjt driver?

I agree, @Toreupfeet have you tried to drive the relay module directly from the ESP.
The 3V3 output should be high enough to activate the relay.

But you will need 5V supply for the relays.

Tom.. :smiley: :+1: :coffee: :australia: