Buttons

Now that we know how to blink an LED, let's learn how to read input from a button. This will let us interact with our Raspberry Pi Pico and make our programs respond to what we do.

Tactile Switch Buttons

Tactile Switch Buttons

How a Tactile Button Works

A button is a small tactile switch. When you press it, the two pins inside make contact and the circuit closes. When you release it, the pins separate and the circuit opens again. Your program can read this open or closed state and respond accordingly.

Button Pin Configuration

A tactile button has four legs arranged in pairs. The two legs on each side of the button are electrically connected together internally. When the button is pressed, the left and right sides become connected, completing the circuit.

Connecting Buttons to the Pico

Connect one side of the button to Ground and the other side to a GPIO pin (for example, GPIO 15). When the button is pressed, both sides become connected internally, and the GPIO pin gets pulled low.

Button connected to Pico

Button with Raspberry Pi Pico 2

Important

What about when the button is NOT pressed? Without anything else, the GPIO pin will be in a floating state - it can randomly read HIGH or LOW due to electrical noise.

This is why we need pull-up or pull-down resistors to give the pin a default, predictable state. We'll cover this in detail in the next chapter.

The Floating Pin Problem

When nothing is connected to an input pin, it doesn't read as HIGH or LOW - it floats. The pin acts like an antenna picking up electrical noise from nearby circuits, your hand, or even radio waves. This causes random, unpredictable readings.

Why Floating Inputs Are Bad

  • Button appears to press itself randomly
  • Unreliable readings that change based on environment
  • Cannot distinguish between pressed and not pressed
  • Program behavior becomes unpredictable

Hardware Requirements

  • Tactile push button
  • Jumper wires
  • Breadboard
  • LED and 330Ω resistor (for testing)
Note

In the next chapter, we'll solve the floating pin problem and create a working button + LED project where pressing the button turns on an LED. This requires understanding pull-up and pull-down resistors.