Push button (6 mm tactile switch)
How to wire a 4-leg tactile push button: which legs are connected, INPUT_PULLUP to GND wiring, and debouncing on Arduino, ESP32 and Pico.
Community draft — report a mistake
3.3 V or 5 V? Wire the button between a GPIO and GND and use the internal pull-up. Never connect a button between a GPIO and 5 V on a 3.3 V board.
The small 6 mm tactile switch from every starter kit has four legs but only two connections: the legs come in pairs that are always joined inside, and pressing the button connects one pair to the other. If your button seems “always pressed”, you have used two legs from the same pair. Using diagonally opposite legs always works.
The simplest reliable wiring is GPIO → button → GND with INPUT_PULLUP turned on. The pin reads HIGH when released and LOW when pressed — so check for LOW in your code.
Mechanical switches bounce for a few milliseconds. For a counter or a toggle, debounce in software; for a “hold to run” button you can usually ignore it.
Pinout
| Pin | What it does |
|---|---|
1 | One side of the switch (one of a pair of legs that are always connected) |
2 | The other side (a leg from the other pair — diagonally opposite works every time) |
Use it with
- Push button (6 mm tactile switch) with Arduino Nano Arduino C++
- Push button (6 mm tactile switch) with Arduino Uno R3 Arduino C++
- Push button (6 mm tactile switch) with ESP32-C3 SuperMini Arduino C++
- Push button (6 mm tactile switch) with ESP32 DevKit V1 Arduino C++
- Push button (6 mm tactile switch) with NodeMCU ESP8266 Arduino C++
- Push button (6 mm tactile switch) with Raspberry Pi Pico 2 W MicroPython
Common errors
Button always reads pressed (or never)
You used two legs that are already joined inside. Use diagonally opposite legs.
Pin reads random values when not pressed
The input is floating. Use pinMode(pin, INPUT_PULLUP) and wire the button to GND.
One press counts as several
Contact bounce. Ignore changes for 20–50 ms after the first edge, or use a debounce library.