Electronic – ESP-32 not working with big motor

esp32gpio-external-interruptinterruptsrelay

I have spent the last two months trying to build a door controller for a chicken coop.

The idea is simple:

  • The ESP32 recieve signal from my house Wi-Fi to close or open the door.
  • So the corresponding relay is triggered while the corresponding limit switch is not closed.
  • When the limit switch is closed, an interrupt is triggered which stop the relays.

With a small fan on the output of the relay, everything is working fine. But once I use a salvage small automatic door motor, the relay stops instantly. I really don't know why but the issue is that interrupts are sometimes triggered without the switch being closed.

schema

I don't think the code could be the issue but here it is. (pastebin.com)

Edit: Updates after recommandations

new schema

  • Added bidirectional TVS diode and 100nF ceramic capacitor on the motor terminal.
  • Added 100uF electrolytic capacitor next to the ESP-32 vin.
  • Added 2200µF cap and 15Ω resistor (RC filter) before the converter.

Result

For the first 3 times everythings was working fine. But after leaving the door open for 3 minutes (so upper switch closed), the ESP32 think the lower switch is closed and instantly stop the relay (I hear a double click). Since then I have tried 3-4 times and it was never working fine, except if the upper switch is not closed when ESP start closing the door.

Best Answer

Inductive kickback and other noise may be making its way to the ESP32, and confuse or even damage it. For a DC motor that turns one way you need a big diode (in reverse, so it doesn't conduct normally) across the motor, and maybe a small capacitor too. See Purpose of the diode and capacitor in this motor circuit, for instance.

For a DC motor that turns both ways like yours, where to put the diode(s) depends on your switching arrangement, see the answer to How to use a flyback diode on a +/-12V motor, or you could use a bidirectional TVS diode, as they are known.

A capacitor of 100nF sounds about OK, there's more to read here: http://pololu.com/docs/0J15/9

As for the P6KE13CA you mention: it has a Vrwm of only 11.1V, and a minimum breakdown voltage of 12.4V, which is a bit tight when using a 12V battery/motor; it will leak a bit, probably no biggie, but I would try finding one with a Vrwm of at least 14v

Also check if the power supply can deliver enough current to drive the motor; if it struggles, voltage will drop and you may suffer a "brown-out".

Related Topic