# ESP32 restarting when relay is turned on

I am designing a PCB with a 5V relay that controls an external DIN mounted latching relay (red line with the "1."):

The problem I have, is that the ESP32 often restarts after turning the latching relay on/off. This only happens if the latching relay is connected. I don't have any problems when the 5V relay triggers without being connected to anything.

When I connect the oscilloscope to the 3.3V rail, I can see a spikes from -40V to 50V (Vpp ~ 90V)

This is my schematic for the Power Supply and relays:

RAC PS datasheet: datasheet
Relay PCN-105D: datasheet
Project full schematic, layout, etc: github

Can those spikes be the responsible of the ESP32 restarting?
What can I do to fix that?

Thanks!

 My probe is connected to the thermal pad of the TO220, and to a pin header where I expose the GND:

And this is my entire setup

• Yup those spikes are most probably reseting your controller! I have seen similar situations. The most simplest and easy solution I see is use an isolator. Since its a relay I think a photocoupler should do the trick. EL817C is cheap and easy to use.
– Bubu
Aug 3 at 17:07
• Already tried a flyback diode at the relays? Aug 3 at 17:12
• @Bubu where would you add the isolator? I think the spikes are coming from the mains. I control the relays using a uln2003a driver Aug 3 at 17:16
• To verify/debug IF it is your power spike are caused due to mains OR lack of isolation, use a battrey to power your digital circuit. If the spikes go away with battrey then your power supply circuit need imporvment. Else if it doesn't help then definetley your digital system needs isolation
– Bubu
Aug 3 at 17:25
• When you attach the scope how do you attach the ground? Aug 3 at 20:13

You can check the reset reason of the ESP32 through esp_reset_reason()

If it's "brownout detector" you know the spikes are the cause and you need better isolation. You could turn-off brownout detection if you want (I do after I discovered that starting a radio when my device was USB powered was doing that), but strongly discouraged because BP is there for a reason.

• Thanks for the tip! I checked the reset reason and it is Power On Reset. I have no clue what it means. Will try with disabling that, to at least be sure that that is the problem Aug 8 at 11:38

I think it is unlikely that you are actually getting those high voltage transients on the 3.3 V logic rail, or you would be seeing damage to those components. More likely the transients form the AC relay coil are being coupled to the scope probe via inductive or magnetic coupling, or through a ground loop. Try connecting the scope probe to the ground point, and you will probably still see significant noise.

Are you seeing this mostly when the relay opens?

Adding a snubber across the AC coil of the relay will probably help. Try something like a 100 ohm resistor in series with a 220 nF film capacitor across the coil to see if it helps.

You could also try adding more capacitors across the 3.3V logic supply, as well as a TVS diode to absorb such transients.

• Yes! I see this mostly when the relay opens. Since the outer it is a latching relay, I turn on the PCB relay and turn it off 200ms later, so I keep it on for a very short amount of time. I am not sure what you mean with Try connecting the scope probe to the ground point. Do you mean both connector from the probe connected to the PCB GND? Aug 8 at 11:41
• Yes. If you still see this noise, it is being picked up by the probe or through a ground loop. If the shorted input shows no noise, you have serious problems on the 3.3V power supply. Aug 8 at 20:43
• @CarlosGarcia Correct probing is vital! See here: m.youtube.com/watch?v=Edel3eduRj4 Aug 9 at 16:22