Relay switcing causing brown out of ESP32

Thread Starter

sirch2

Joined Jan 21, 2013
1,075
Transient.jpg

I am driving a couple of relays from an ESP32, some combination of switching the two relays gives the above tranisent on the ESP32 power lines which is enough to cause a brown-out. The whole thing is driven from an ~18v battery (or bench PSU) with buck converters to give 12v for the relays and 3.3v for the ESP. The relays have flyback diodes and 100uF capacitors across them and are switched from the ESP by low-side BJTs. I've tried a range of capacitors on the input to the ESP including things like 220uF electrolytic plus a 100nF ceramic, etc but this keeps happening.

Switching one or other relay independently is okay but some combination of switching them both close together, there is always about 200mS delay between switching them off causes this. it was all working fine on the bench but when I got it into the enclosure this started happening and now it happens on the bench too. Any ideas as to how I suppress this?
 

panic mode

Joined Oct 10, 2011
5,219
schematics? pictures? what kind of enclosure? if it worked on the bench but not inside enclosure, my first suspicion is that it is a metal enclosure and mounting board there introduced ground loops, which did not exist when board was on the bench. and please crop/resize images in your posts. 1200 pixel horizontal is plenty...
 

B-JoJo-S

Joined Jan 3, 2026
503
Out of my comfort zone here - but a relay coil is basically a coil; and a capacitor in combination forms a tank circuit. Your trace looks like a tank circuit. Have you tried switching them without the cap? You're correct in using a flyback diode, so don't remove that.

Alternatives: Can you use a MOSFET to do the switching instead of the relay?

Questions: Exactly how is the cap on the relay? Across the coil? In series with the coil (which shouldn't work if the relay is DC powered)
Are you switching an AC source?
Is your relay contacts SPDT or DPDT (or 3P or more / DT)?

EDIT: See https://www.allaboutcircuits.com/te...rrent/chpt-6/parallel-tank-circuit-resonance/
END EDIT.
 

Thread Starter

sirch2

Joined Jan 21, 2013
1,075
Out of my comfort zone here - but a relay coil is basically a coil; and a capacitor in combination forms a tank circuit. Your trace looks like a tank circuit. Have you tried switching them without the cap? You're correct in using a flyback diode, so don't remove that.
Good call regarding the tank circuit, initially I didn't have the caps but I was getting a different brown out issue, its been through several iterations so perhaps no caps on the relays but more/different on the ESP power lines might work
 

Reloadron

Joined Jan 15, 2015
7,926
While I am unsure of your exact relay config I have had no problems using relay boards single channel up to 16 channel relay boards similar to these. This includes ESP 32, ESP 8266 and other assorted uC projects. They all work just fine. If all else fails I would give a relay board a shot. Newer boards like I linked to include I2C communication.

Ron
 

panic mode

Joined Oct 10, 2011
5,219
same here... properly used relays are not a problem. to determine problem we need to see entire circuit and construction. also it would be nice to get confirmation if bench tests included loads. maybe problem is not the control side, it is the load side.... also how is the ESP power derived/maintained? any caps to filter out glitches here?
 
First question: WHAT is the purpose of the capacitors across the relay coils?? I see no possible benefit from that, only a greatly increased inrush current for the control device. A capacitor across the power source could make sense, but not across the relay coil. The diode across the coil will clamp the flyback pulse AND ALSO slow the drop-out of the relay a small amount.
 
Hello, from experience I rarely drive relays with an ESP32 (or some other microcontroller) directly without some form of buffer (or maybe circuit that slows down the signal slew rate that activates the relays)
i.e. microcontroller (ESP32) => demux => buffers => relays as I've designed automation systems with lots of relays (and even with this consideration in mind I still get problems with relay bounce from time to time)
(There's also a need to ensure each relay is driven with enough current from the buffer)

Hope this helps somehow.
Cheers,
Justin
 
Certainly driving a transistor to control the relay is a better choice, unless the required relay coil currents are within the specified capability of ESP32 you are using. BUT using an external transistor as the driver is a good choice, although certainly it is much less convenient. Adding a buffer stage should also provide some protection against the inductance effects on the voltage and current, and added currents that are not so obvious, in other portions of the current loop.
 
Using disgram in Post #4, any large caps should be connected to pin 1 of the relay and to GND to provide surge current during relay switch. Absolutely no caps across relay coil or at switching transistor.
Next, you are showing 3.3V supply and current surge would be on +12V supply. Without sufficient bulk capacitance on the output of the +12V supply your current surge would work its way back to the 18V supply and cause voltage brownout at 18V thereby affecting 3.3V supply.
That said the scope trace does not show a voltage droop as much as possibly ground bounce. You need to pay attention to your grounding especially if this is a bunch of loose wires or proto board. Try creating two sepearte GND distributions, +3.3V and +12V and the tie these two GNDs together, preferably at the output of both buck regulators.
 
The one place where a capacitor across a relay coil works is when the DC ciol relay is driven by a diode rectified AC signal, such as the output of an audio amplifier. And with tube type relay drivers in some time delay circuits. Back in 1960.
 
Top