EngineeringMaker Lab

Build guide

Featured project

Read a Push Button with Raspberry Pi Pico

Add a push button to the LED circuit from Project 001 and make the light respond to you. In 20–30 minutes, you will read a digital input on GP14 and control an LED on GP15 using MicroPython.

Last updated

Build Time
20–30 minutes
Estimated Cost
Included in the recommended starter kit
Skill Level
Beginner
Raspberry Pi PicoFirst StepsRaspberry Pi PicoPush ButtonDigital InputMicroPython

Project overview

What You Will Build

A push button is a temporary electrical switch. Pressing it joins two contacts; releasing it separates them. That simple change gives a microcontroller a way to sense a person’s action and decide what should happen next.

Inputs matter because interactive systems need information from the world before they can respond. Buttons, switches, and sensors all turn real events into values a program can read. This project builds directly on Blink an LED: the Pico still controls an LED on GP15, but now a button on GP14 decides when the light turns on.

This implementation uses the Pico’s internal pull-up resistor. GP14 normally reads HIGH, and pressing the button connects it to GND so it reads LOW. Follow the original diagrams for the circuit overview, then use the official SunFounder resources for the complete vendor-specific build walkthrough.

Engineering Teacher Tip: An unconnected digital input is “floating,” so tiny amounts of electrical noise can make it jump unpredictably between HIGH and LOW. A pull-up or pull-down resistor weakly connects the input to a known voltage when the switch is open. That dependable default state is essential anywhere a digital signal might otherwise be left disconnected.


Skills

What You Will Learn

  • Understand digital input
  • Learn how push buttons work
  • Learn pull-up and pull-down concepts
  • Read a GPIO input
  • Control an LED using a button

Preparation

Parts Used

Gather these components before starting the build.

  • Qty: 1Raspberry Pi PicoWith header pins installed
  • Qty: 1BreadboardSolderless breadboard
  • Qty: 1Push buttonFour-leg momentary tactile switch
  • Qty: 1LEDStandard through-hole LED
  • Qty: 1220 ohm resistorLimits current through the LED
  • Qty: 4Jumper wiresMale-to-male
  • Qty: 1USB cableData-capable cable for programming

Verified resource

Complete Official Build Guide

Reading Button Value

Already have the recommended equipment? The verified SunFounder lesson provides the exact wiring, schematic, code, and step-by-step build instructions.

The verified Thales MicroPython lesson provides the exact button wiring, schematic, code, and step-by-step build instructions.

Original preparation

Original Code and Preparation Notes

This independently written example summarizes the programming concept used by the project. Compare wiring and pin choices with the verified official guide, when available, before running main.py.

main.pypython
from machine import Pin
from time import sleep

# The internal pull-up keeps GP14 HIGH until the button connects it to GND.
button = Pin(14, Pin.IN, Pin.PULL_UP)
led = Pin(15, Pin.OUT)

while True:
    if button.value() == 0:  # A pressed button reads LOW.
        led.on()
    else:
        led.off()

    sleep(0.02)  # A short pause keeps the loop stable.

Understand it

How the Code Works

  1. GP14 is configured as a digital input with the Pico's internal pull-up resistor enabled.
  2. The released button reads HIGH because the pull-up gives the input a known default state.
  3. Pressing the button connects GP14 to GND, so button.value() becomes 0 and the LED turns on.
  4. GP15 controls the external LED through its 220 ohm current-limiting resistor.

Problem solving

Common Beginner Mistakes

The button always reads HIGH

Confirm the switch bridges the breadboard center gap and that pressing it connects the GP14 side to the GND side. Rotate the switch 90 degrees if both jumpers are on permanently connected legs.

The button always reads LOW

Check for an accidental direct connection between GP14 and GND

The input changes without pressing the button

A floating input has no reliable default voltage. Enable Pin.PULL_UP exactly as shown and keep the GND connection secure.

The resistor is placed incorrectly

The 220 ohm resistor belongs in series between GP15 and the LED anode. This version uses the Pico's internal pull-up

The LED does not respond

Test its polarity and trace GP15 through the 220 ohm resistor and LED to GND

The code uses the wrong GPIO pin

The button must connect to GP14 and the LED must connect to GP15. Match both physical pin labels to Pin(14) and Pin(15) in the code.

Common questions

Frequently Asked Questions

Why do buttons need pull-up or pull-down resistors?

An open button otherwise leaves its input without a defined voltage. A pull resistor gives the pin a dependable default HIGH or LOW state.

What is a floating input?

It is an input disconnected from a clear HIGH or LOW voltage. Electrical noise can then make its reading change unpredictably.

Can I use the Pico internal pull-up resistor?

Yes. This project enables Pin.PULL_UP on GP14

Why doesn't my LED respond?

Check the button orientation

Project complete

Next planned project: RGB LED

This project is planned for the learning path but has not been published yet.