Random open/close on reed circuit

Hi,

I have a 4 channel relay board with and ESP32 in the same PCB that I bought from AliExpress. The ESP model on the IC is esp32-wroom-32e.

I use the 4 relays to open/close 2 garage doors and they work well.

I however am using one of the pins GPIO16 connected to a limit switch to confirm if the door is open or closed. I am connecting the other wire of the limit switch to GRND on the same board. The limit switch is around 6 meters away. It was working well for a long time but recently, when the limit switch is not engaged (open) it starts to detect a close/open within milliseconds. At first I thought it was some debounce so I added debouncers but it continued happening. Then I thought maybe the wire and connectors have something wrong so i replaced both but it continues happening.

I am at wits end on what else I could look into. Any ideas or suggestions on what to look for please?

[15:45:47][C][mdns:116]:   Hostname: xxx
[15:45:47][C][ota:097]: Over-The-Air Updates:
[15:45:47][C][ota:098]:   Address: x.x.x.x:3232
[15:45:47][C][ota:101]:   Using Password.
[15:45:47][C][api:139]: API Server:
[15:45:47][C][api:140]:   Address: x.x.x.x:6053
[15:45:47][C][api:142]:   Using noise encryption: YES
[15:48:01][D][binary_sensor:036]: 'Garage Door': Sending state OFF
[15:48:01][D][binary_sensor:036]: 'Garage Door': Sending state ON

The connects/disconnect above is what i am referring to.

esphome:
  name: xxx
  friendly_name: xxx

esp32:
  board: esp32dev
  framework:
    type: arduino


-rest of yaml-

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO16
      inverted: false
      mode:
        input: true
        pullup: true   
    name: "Garage Door"
    device_class: garage_door
    filters:
      - delayed_on: 1s
      - delayed_off: 1s

Whats the voltage AT the switch?

Try install a physical pull-up resistor (like 2,200 ohms) between 5v and GPIO16, then turn off the pull-up in the yaml.
Also if the limit switch is actually based on a reed-switch, those can fail after some time and remain open.

Thanks for your help.

I managed to solve it by connecting the reed between 3.3v and GPIO16 instead of GND and GPIO16 and then set the pin to inverted true and pulldown.

Seems to be working well :slight_smile: