Source: https://mokxi.com/learn/raspberry-pi-pico-button
Updated: 2026-10-05

Learn

# Read a button on a Raspberry Pi Pico

Beginner

Written by the Mokxi team, updated October 5, 2026

Start building free Open the editor

Or see every lesson.

- 261 parts on the bench
- 31 boards running now
- 1.00x real time, on every board

Hold the button

A pushbutton from GP15 to GND, read with the internal pull-up. Hold it and the LED on GP25 lights.

To read a button on a Raspberry Pi Pico, wire it from a GPIO pin to GND, turn on the pin’s internal pull-up with pinMode(pin, INPUT_PULLUP), and read it with digitalRead(): HIGH means up, LOW means pressed. No resistor is needed.

The circuit above is a Pico with a pushbutton between GP15 and GND. While you hold the button, the LED on the board, on GP25, lights. It runs in your browser on a simulated RP2040, and the sketch is Arduino-style C++ that compiles for a real Pico too.

## What you need

- A Raspberry Pi Pico
- A pushbutton (a four-leg tactile switch)
- Two jumper wires
- Optional: an LED and a 220 ohm resistor on GP14, which the sketch lights too

## Wiring

Part and pin | Goes to | Note

Button, one leg | GP15 | The pin the sketch reads

Button, the leg across from it | GND | Any GND pin on the Pico

LED (optional), through 220 ohm | GP14 | Lights with the on-board LED

## Step 1: wire the button to ground

A four-leg tactile switch is two pairs of legs. The legs in a pair are always joined, and pressing the button joins one pair to the other. Wire one leg to GP15 and a leg on the other side to any GND pin. If the button seems to be pressed all the time, you have used two legs of the same pair: turn it a quarter turn.

That is the whole circuit. GP15 is the bottom pin on the Pico’s left side, with a GND pin a few pins up, so on a desk it is two short wires and no breadboard at all.

## Step 2: why INPUT_PULLUP

An input pin with nothing driving it floats. It picks up whatever is nearby and reads HIGH and LOW at random. The cure is a resistor that pulls the pin to a known level when the button is open. The RP2040 has one built into every GPIO, so pinMode(BUTTON, INPUT_PULLUP) switches it on and the pin rests at 3.3 V.

Pressing the button connects the pin straight to ground, which wins against the weak pull-up, and the pin reads LOW. So the logic is upside down from what you might expect: LOW means pressed. The sketch turns that around in one line before it drives the LEDs.

## Step 3: the code, explained

setup() makes GP15 an input with its pull-up, and makes the on-board LED and GP14 outputs. LED_BUILTIN is GP25 on a Pico. loop() reads the button and writes the result to both LEDs, over and over, so the LEDs follow your finger.

Because the LED simply mirrors the button, contact bounce does not matter here: a few fast flickers at the instant of the press are too short to see. Bounce matters as soon as you count presses or toggle something on each press, which the debounce tutorial covers.

The Pico button example

## Step 4: make it toggle

A button that turns the LED on with one press and off with the next needs two changes. Remember the last reading, and act only when it changes from HIGH to LOW, which is the moment of the press. Then ignore the button for a few tens of milliseconds, so the bounce does not count as more presses.

Toggle on each press

## Try it in the editor

Open the circuit in the editor and hold the button with the mouse: the LED on the board lights. Replace the sketch with the toggle version above and press Run again. Then add an LED and a 220 ohm resistor from GP14 to GND and watch it follow the board’s LED.

To see what the pull-up is for, turn on Show levels with Shift+L, which labels every wire with its level while the circuit runs. Then change INPUT_PULLUP to INPUT and run it again. With the button up, nothing holds the pin at either level any more: that floating input is exactly what the pull-up was there to prevent.

## Common mistakes

Wiring the button to 3V3 instead of GND while using INPUT_PULLUP. The pin is already pulled up, so pressing changes nothing. With the pull-up, the button goes to ground.

Using two legs of the same pair. They are joined inside the switch, so the pin reads pressed all the time. Use legs on opposite sides.

Expecting HIGH when pressed. With a pull-up, pressed is LOW. Either test for LOW, or wire the button to 3V3 and use INPUT_PULLDOWN, which the RP2040 also has.

Using GP25 for an external LED. GP25 is wired to the LED on the board and is not on the header, so an external LED goes on another pin, like GP14 here.

## Questions

Do I need a resistor for a button on a Pico?

Not if you use INPUT_PULLUP or INPUT_PULLDOWN. Every RP2040 GPIO has a pull-up and a pull-down built in. An external 10 k resistor does the same job and is only needed if you turn the internal ones off.

Which Pico pins can read a button?

Any GPIO, GP0 to GP22 and GP26 to GP28. GP15 is used here because it sits near a GND pin. GP23 to GP25 and GP29 are used inside the module.

Can I use MicroPython for this?

Not in Mokxi, which runs Arduino-style C++ compiled for the RP2040. The idea is the same in MicroPython: Pin(15, Pin.IN, Pin.PULL_UP), and value() is 0 while the button is pressed.

Why does my button register several presses?

The contacts bounce for a few milliseconds when they close. Act only on the change from HIGH to LOW and ignore the pin briefly afterward, as the toggle sketch above does, or see the button debounce tutorial for a method that does not use delay().

Related

## Keep going

Pull-Up Resistors and the Floating Input They Fix Arduino Button Debounce: See the Bounce, Then Fix It Debouncing a Button: Why It Fires More Than Once Raspberry Pi Pico PWM: Slices, Channels and 1 kHz Arduino Uno vs ESP32 vs Pico: Which to Learn First? The pushbutton, pin by pin The Pico button project Beginner The Raspberry Pi Pico simulator What the Pico model runs The project page, with the full sketch Beginner

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
