Pushbuttons, pull-ups and debouncing
Wire an active-low button correctly, reject contact bounce, and turn a held press into one event.
A pushbutton is a switch, not a reliable voltage source. An input left disconnected can change unpredictably. For a UNO beginner circuit, connect D2 to one switched button contact and ground to the other, then select INPUT_PULLUP. The internal pull-up supplies the released HIGH state; a press creates a LOW state. This wiring needs no external pull-up resistor.
Four-legged tactile buttons normally have two pairs of internally joined pins. Check the pairs with a continuity meter while power is removed. If you connect the same joined pair, pressing may appear to do nothing because the input is already permanently connected to ground. Straddling the breadboard center gap often helps, but verify your exact switch.
A single physical press can make several rapid electrical transitions as the contacts settle. A debounce filter remembers the latest raw state and when it changed. Only accept that state after it remains unchanged for a chosen interval, such as 25 ms. Increase the interval if your particular switch still creates duplicates; excessive delay makes the control feel sluggish.
Keep raw and accepted states separate. When raw changes, save changedAt = millis(). Once the raw state differs from the accepted state and uint32_t(now - changedAt) is at least the interval, update the accepted state. With active-low wiring, an accepted transition to LOW is a press event, and an accepted transition to HIGH is a release.
A press event differs from a pressed level. Testing LOW on every loop can count hundreds of presses while a finger holds the switch down. Count only the transition, and require a release before accepting another. The Arduino Reaction-Time Game uses this distinction for starting, rejecting a false start and recording one result.
Test five deliberate presses, a held press, a quick tap, and a button already held at power-up. Compare the event count with what you actually did. Check the wiring before trying a larger software delay. Long loose wires can add noise; keep the first prototype compact.
Disconnect power before moving wires. Never use a button to connect a GPIO directly to an opposing output driven by another pin. Reference: Arduino INPUT_PULLUP documentation and its built-in Debounce example: https://docs.arduino.cc/built-in-examples/digital/Debounce/

