3
\$\begingroup\$

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.

\$\endgroup\$
16
  • 1
    \$\begingroup\$ PSU problem here. \$\endgroup\$ Sep 25, 2020 at 11:19
  • \$\begingroup\$ What is the distance from home for the coop? Did you tought about the possibility of using a commercial garage-door control circuit, at 433.32MHz range, with built-in reed sensors, everything professionaly built from the start for this application, instead of using Wi-Fi, a fancy MCU, and generic relay modules? \$\endgroup\$
    – mguima
    Sep 25, 2020 at 12:32
  • 3
    \$\begingroup\$ @ocrdu's answer is reasonable. If you can't add a diode to the motor due to reversing then two series opposed zeners at 12V+ will do quite well. (Zener Vf is about 1V+ so 12V zener + one as a diode is ABOUT 13V+). || Also if motor and electronics share a common supply, add a series R in electronics feed with a large cap and zener to ground before any regulator. RC acts as filter and zener discourages spikes there and then regulator has an easier job. \$\endgroup\$
    – Russell McMahon
    Sep 28, 2020 at 13:29
  • 1
    \$\begingroup\$ You seem to have ignored this suggestion of mine (see above comment): " ... Also if motor and electronics share a common supply, add a series R in electronics feed with a large cap and zener to ground before any regulator. RC acts as filter and zener discourages spikes there and then regulator has an easier job. ..." -> Do this on the input to the mini-360. || Report back. \$\endgroup\$
    – Russell McMahon
    Oct 1, 2020 at 13:38
  • 2
    \$\begingroup\$ @Mathix420 Resistor must drop LESS voltage than is available to waste at the Mini-360 input. You have about 7V "headroom" BUT you are using a converter to gain efficiency. | Rseries = V/I = Vdrop_desired/Imax. | For eg 2V drop and 500 mA max current R=V/I = 2V/0.5A = 4 Ohm. C is on Mini-360 side of R. As big as reasonably possible. eg 100 uF OK, 1000 uF better. I mentioned a zener but without one OK as a good start. This MAY fix all issues - if not ask again and we can suggest more. \$\endgroup\$
    – Russell McMahon
    Oct 2, 2020 at 2:55

2 Answers 2

3
\$\begingroup\$

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 +/-12 V motor, or you could use a bidirectional TVS diode, as they are known.

A capacitor of 100 nF 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.1 V, and a minimum breakdown voltage of 12.4 V, which is a bit tight when using a 12 V battery/motor; it will leak a bit, probably no biggie, but I would try finding one with a Vrwm of at least 14 V.

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".

\$\endgroup\$
7
  • \$\begingroup\$ Thanks for your help! I'd add the cap and the diode, also going to test the PSU today I'm telling you back. What value should I use for the cap (100nF?) and which diode? Also, should I use two diodes since I'm using this motor in the two directions? \$\endgroup\$
    – Mathix420
    Sep 25, 2020 at 14:06
  • 1
    \$\begingroup\$ Where to put the diode(s) would then depend on your switching arrangement, see the answer to electronics.stackexchange.com/questions/322120/…, or you could use a bidirectional TVS diode, as they are known. The capacitor sounds about OK, there's more to read here: pololu.com/docs/0J15/9 \$\endgroup\$
    – ocrdu
    Sep 25, 2020 at 14:30
  • \$\begingroup\$ Thx for the links, very instructive! I'm going to buy some TVS diodes (P6KE13CA). Also I've check the PSU and no issue for delivering enough current (less than .05v drop). \$\endgroup\$
    – Mathix420
    Sep 26, 2020 at 9:57
  • 1
    \$\begingroup\$ I'm not exactly a TVS specialist, but the P6KE13CA 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. \$\endgroup\$
    – ocrdu
    Sep 26, 2020 at 10:12
  • 1
    \$\begingroup\$ Please post the right solution in the answer not in the comments, somebody might burn something using the example in the answer for a bridge configuration as I see from the schematic. \$\endgroup\$
    – Dorian
    Sep 28, 2020 at 13:16
2
\$\begingroup\$

The start-up current for a motor is high and can drop the voltage under the minimum required by the DC-DC converter. It's not only about the battery current capability but also about the thickness of the wires you use and connectors (I hope you don't use a breadboard for this). You should protect the converter from short voltage drops by using a circuit like this:

schematic

simulate this circuit – Schematic created using CircuitLab

The diode should have a peak current of at least 5A, I don't know which is available in your area.

If the voltage drop at motor start is visible (>3V) using a multimeter then you also need a bigger battery.

You might also try smaller resistors (~1K) or, better, hardware debouncers on the switches if the ESP is not restarting.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for helping me! I have check for a voltage drop and don't see any on the multimeter. Maybe it's too fast. Thikness of the wire is about 2mm between battery and DC-DC converter, but for converter -> ESP it's pretty small. Wouldn't a smaller resistor make the switches more sensitive? \$\endgroup\$
    – Mathix420
    Oct 1, 2020 at 10:18
  • 1
    \$\begingroup\$ @Mathix420 No, a smaller resistor will make the input less sensitive to noise due to higher pull-down current. The wires are fine if the ESP it's not restarting. I wold point that the setup with switches between IO and +3.3V is risky in case some wire is broken, you might short the 3,3V line to chassis which is dangerous, better use inverted logic and use ground as active level like in the debounce link. \$\endgroup\$
    – Dorian
    Oct 1, 2020 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.