Issue: esp32 shuting down when triggering relay

Hello everyone,
i have a problem using a Relay with my esp32 witch is controlled by espHome and HA.

Parts that i use:

  1. esp32 (ESP32DevKitC V2): Link
  2. relay (5V DC): Link
  3. pump (5V): Link
  4. Humidity sensor: Link)

Setup:


Note: The Battery is a Lipo 2s 7.4V. This is because i use the 5V BEC i took from my RC. Also the parts are mostly the placeholders of the used parts. Important information is here the wiring and the connections to the parts.

The Code and the development of the code is here: Link

What i want it to do:
When the Value of the Moisture is under a certain threshold the esp should trigger a GPIO and so switch the relay on, witch will switch then the pump on. After 15sec its should switch the Pump off and go to deep sleep.

What it does:
When the esp switches the relay on and no pump is connected to the relay, everything works fine and works according to plan. When i connect a consumer e.g. the pump to the relay the esp 32 switches the pump on and after around a second everything shuts down and the esp reboots.

What i tested so far:

  1. Pump got is own battery connection. Esp32 and the rest powered by USB-Port from the esp32

    I did this to check if the pump draws to much current and the drop in voltage is to rough to handle for the esp, but no change in the strange behavior.
  2. Tested different Pins connections to the relay as trigger. I thought maybe some GPIOs are better suited or somthing… Also no change.
  3. I had two of the relays and changed it. Problem remained.

Iam running out on ideas what the problem could be. Maybe somone of you guys have an idea or experinced somthing similiar?
Thank you in andvance for support!

Opening and closing relays with an inductive load (ie. a coil in a relay) causes small voltage spikes or noise.

If you are using the standard cheap relay as shown in the pictures above, there shouldn’t be a problem, the esp should be able to handle the noise from those relays. As the issue remains when you swap relays, it might be due to a (somewhat) faulty ESP board/chip.

You could try mounting a flyback diode across the relay pins. For info on choosing a flyback diode see: How to choose a flyback diode for a relay? - Electrical Engineering Stack Exchange

A 1N4007 or 1N4001 should work. Solder the diode across the red and black pins on the esp side of the relay (under the relay board). In reverse, that is.

If that doesn’t work, try another GPIO pin.

Hello,
thank you for your suggestions. I ordered a new esp32 from an onther manufacturer because i had the same idea of a faulty esp.
When i have it, im going to test it and when the problem rimains i will try your diode idea.

What do you mean for trying an other GPIO? I tried differend GPIO as trigger for the relay. The problem remained.

Sometimes a single gpio pin is damaged and the rest works fine.

To prevent frying your ESP please try the diode first before trying a new esp. Might be that the flyback current from the relay coil fried your original esp.

Sorry, after this issues is lost interest in this project.
But last week i tryed it with another pump and everything worked flawlessly.
My impression is that the pump is not properly shieldet and producing EM interferences that somehow interfere with the esp. For example when the pump was running my cordless Headphones lost their connection. :smiley:
Thank you for your Help!
The topic is now closed.