Raspberry Pi Pico Push Button: Wiring, Code and Simulator
To build this Raspberry Pi Pico Push Button project you need a Raspberry Pi Pico and a 220 Ω resistor, a red LED and a push button. A button on GP14 with Pin.PULL_UP lights the LED on GP15 while held. Make the 5 connections in the wiring table, upload the MicroPython code, and hold the button; the serial monitor says pressed and released.
Open this circuit in the free Raspberry Pi Pico simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Raspberry Pi Pico | the microcontroller board |
| 1 | 220 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | red LED | Lights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor. |
| 1 | push button | Connects 1 to 2 while held. Pair with INPUT_PULLUP and wire the other side to GND. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Raspberry Pi Pico GP15 | 220 Ω resistor leg 1 |
| 2 | 220 Ω resistor leg 2 | red LED anode (A, long leg) |
| 3 | Raspberry Pi Pico GND | red LED cathode (C, short leg) |
| 4 | Raspberry Pi Pico GP14 | push button 1.l |
| 5 | Raspberry Pi Pico GND | push button 2.r |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Raspberry Pi Pico. No install or account is needed.
- Add the parts. Add a 220 Ω resistor, a red LED and a push button from the parts palette.
- Wire 1. Connect Raspberry Pi Pico GP15 to 220 Ω resistor leg 1.
- Wire 2. Connect 220 Ω resistor leg 2 to red LED anode (A, long leg).
- Wire 3. Connect Raspberry Pi Pico GND to red LED cathode (C, short leg).
- Wire 4. Connect Raspberry Pi Pico GP14 to push button 1.l.
- Wire 5. Connect Raspberry Pi Pico GND to push button 2.r.
- Paste the MicroPython code. Paste the MicroPython code below into the code editor.
- Run it. Press Run. Hold the button; the serial monitor says pressed and released.
MicroPython code
# Button: GP14 with the internal pull-up; pressing it lights the LED on GP15.
from machine import Pin
import time
button = Pin(14, Pin.IN, Pin.PULL_UP)
led = Pin(15, Pin.OUT)
last = 1
print("Press the button.")
while True:
now = button.value()
led.value(1 - now) # pressed reads 0
if now != last:
print("pressed" if now == 0 else "released")
last = now
time.sleep_ms(10)
What to try
Hold the button; the serial monitor says pressed and released.
Frequently asked questions
How do I wire the Push Button project on a Raspberry Pi Pico?
Make 5 connections: Raspberry Pi Pico GP15 to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to red LED anode (A, long leg); Raspberry Pi Pico GND to red LED cathode (C, short leg); Raspberry Pi Pico GP14 to push button 1.l; Raspberry Pi Pico GND to push button 2.r.
What parts do I need for this Raspberry Pi Pico project?
A Raspberry Pi Pico and a 220 Ω resistor, a red LED and a push button.
Can I simulate this Raspberry Pi Pico project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and MicroPython code in your browser for free, with no install and no hardware. The RP2040 is emulated and runs the official firmware.
What does the code do?
A button on GP14 with Pin.PULL_UP lights the LED on GP15 while held.
More Raspberry Pi Pico projects
- Raspberry Pi Pico LED Blink: Wiring, Code and Simulator
- Raspberry Pi Pico ADC + PWM LED Dimmer: Wiring, Code and Simulator
- Raspberry Pi Pico NeoPixel Ring: Wiring, Code and Simulator
- Raspberry Pi Pico DHT22 Sensor: Wiring, Code and Simulator
- Raspberry Pi Pico I2C LCD: Wiring, Code and Simulator
- Raspberry Pi Pico LED Blink: Wiring, Code and Simulator