Adding temperature sensor and door bell switch to ESP32

Hi, I’m currently using esp32 as BLE to detect if I’m home or away. I would like to add the temperature sensor and also detecting the door bell button pressed.

For adding the temperature sensor, there is plenty example and I found no issue to follow them.

But to detect the door bell button pressed, I don’t know how should I connect the wires. I’m not using any door bell now but I do have the door bell switch at attached outside of my house and there are two wires routed to inside.

How can I use the two wires and connect to my esp32 board to detect the button being pressed?

Thanks.

Connect one side of your doorbell button to the ESP ground (not important which side of the button).

Connect the other side of your doorbell button to a GPIO on your ESP.

Create a GPIO binary sensor for this GPIO.

Enable software pullups and invert the sensor.

binary_sensor:
  - platform: gpio
    name: Doorbell
    pin:
      number: GPIO15
      pullup: true
      inverted: true

To be clear, that would be for a doorbell exclusively hooked to the ESP.
Don’t hook the ESP in parallel with existing wiring to, e.g, an actual bell.

So I don’t need to connect actual resistor for pullup/pulldown?

Yes. It will be exclusive.

Nope. You can use one connected internally in the ESP32.

Nice eh?

Just make sure you dont use GPIO34 to 39. They don’t have software pulliups.

See here for a handy reference (scroll down to the table):

1 Like

I wasn’t aware there is pullup/pulldown build in the esp32. That’s nice!
Thanks for the prompt reply.

Yesterday I have tried to connect the 2 wires from the door bell switch to GPIO15 pin and the GND pin on the esp32. And then updated the configuration, and initially all good.

The reported state is correct initially when I pressed the door bell switch. But after a while, I’m getting alot of the false trigger.

The esp32 board is very close to the power outlet, wasn’t sure if there is any EMI coming from power outlet causing the false trigger.

Any suggestions?

Add a 0.1uF ceramic or multi-layer-ceramic (MLC) capacitor (any voltage rating) between the GPIO and GND on the ESP board and see if that improves things. Try and keep the capacitor leads as short as possible.

So you are suspecting there is leakage between GND and GPIO pins and adding a DC blocker cap to block the leakage?

I’ll try your suggestion once I have acquired the cap. Meanwhile I will try to use another GPIO15 or another GND pin and see it’s improve the situation.

Thanks.

No, I suspect there is mains hum on your switch cabling. The capacitor is connected in parallel with the push button, not in series, it’s not blocking anything. It shunts the hum to ground.