How to Wire and Program a Button

I thought @LarryD's diagram about wiring was good:


Wokwi - Online ESP32, STM32, Arduino Simulator

Also:

And there are good references at

Also, there is a completely different example for INPUT_PULLUP wiring:

https://docs.arduino.cc/built-in-examples/digital/InputPullupSerial/