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.
I don't think the code could be the issue but here it is. (pastebin.com)
Edit: Updates after recommandations
- 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.