I have connected up a micro switch to 3.3v and pin D1 on a nodemcu, I want to detect when a door is locked or unlocked but I am getting incredibly weird behavior, the switch is not faulty I have swapped it out with another micro switch, have tried a reed switch and even a traditional switch and all do exactly the same.
When the switch is toggled it should be either on or off depending on its position but it goes into a weird non stop loop and constantly switches between on and off (see image below and look at the timestamps), state changes are in the region of 15-20 per second.
If I test with a multimeter when its doing this the switch and board are either in the on or off position and is not actually cycling the on / off position as the software is showing.
I’m stumped, any ideas why it would be doing this?
- platform: gpio
Thanks for the feedback, I’ve tried mode: INPUT_PULLUP previously as I read about it online but it gives me an error in ESPHome "[mode] is an invalid option for [binary_sensor.gpio]. Please check the indentation.
Can I try just with the resistor without having that in there or would it not work?
This works too. When you use INPUT_PULLUP, it connects an internal resistor, so you don’t technically need the external one. Alternatively, you can use your external resistor and you could use the default with just INPUT too. But I don’t think there is anything wrong with how you have it setup. Just wanted to clarify.
No need to desolder unless you are personally curious IMO. If your wires are long and have interference, the internal pull-up resistors may not be sufficient. I think they are something like 50k ohm, so yours provides stronger pull-up which can alleviate minor noise issues as well.