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.
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.
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.
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?
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..
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.
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.
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..