A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By btidey
#87456 Is there a pull up resistor on the GPIO?

If not then when you release the button then the GPIO is essentially just floating and could be any value.

Either put a pull up e.g. 10K from GPIO to 3.3V or change the pinMode to INPUT_PULLUP. The latter will use an internal pull up of around 36K which is OK providing the leads to the button are reasonably short.