I have a garage door controller built using an ESP32 and ESPHome. It’s a very basic design using a normally closed reed switch. The problem is that when the door is open, the sensor will periodically report the door closing for a fraction of a second, and then opening again. Happens a few times a minute. When the door is actually closed, it only reports closed, and does not bounce.
Is there anything wrong with this configuration? I don’t think I’ve got a bad connection - if I did, I’d expect it to also have issues when the door is closed.
If they are long then they act as an antenna picking up all sorts of RFI.
When your reed switch is shorted to ground this is not an issue, as all the RFI conducts to ground.
When your reed switch is open the pullup is a relatively high impedance (~50K Ohm), so the voltage fluctuates.
Solution: Add a 0.1uF capacitor from the GPIO to ground. This will conduct away high frequencies. You could also add a lower value physical pull-up resistor (~1K Ohm).
Alternate solution: move the ESP close to the reed switch so the cables are less then 30cm / 1 foot.
Using shielded twisted pair cable may also help. Ground the shield at one end only.
They’re long. Maybe 15 feet or so. It seemed easiest at the time to mount a little box above the garage door opener, and run cable to the door for the sensor, so that’s what I did.
I added a .1uF capacitor across the reed switch, and that seems to have done the trick. Thanks!
Sorry, I realize that was confusing. I meant electrically speaking. The capacitor is in the box with the ESP32. Both the reed switch and the capacitor have one leg connected to the GPIO, and one to ground. So in that sense, the capacitor is connected “across” the reed switch. But it’s physically connected to the GPIO.