3. Read a pin
You will be able to
- make a pin an input and read its level,
- use an internal pull-up or pull-down,
- explain what a floating input is and why it behaves randomly.
You need: a push button, a 330 Ω resistor, an LED. Problems: Button mirror, Reaction game.
The idea
An input pin does not drive anything. It looks at the voltage on its net and answers one question: is this closer to 0 V or 3.3 V?
That only works if the net has a defined voltage. A pin connected to nothing is floating: it picks up stray charge and can read high, low, or change when you move your hand. The fix is a pull — a weak resistor inside the chip that gently ties the pin to 3.3 V (pull-up) or 0 V (pull-down).

The exact tools
| What | MicroPython |
|---|---|
| An input | Pin(12, Pin.IN) |
| An input with a pull-up | Pin(12, Pin.IN, Pin.PULL_UP) |
| An input with a pull-down | Pin(12, Pin.IN, Pin.PULL_DOWN) |
| Read it | button.value() → 0 or 1 |
Build it
Wire a button from GP12 to 3V3, and the LED from lesson 1. Use a pull-down, so the pin reads 0 when nothing is pressed:
from machine import Pin
import utime
button = Pin(12, Pin.IN, Pin.PULL_DOWN)
led = Pin(13, Pin.OUT)
while True:
led.value(button.value())
utime.sleep_ms(10)
Press Run and hold the button. The LED is a mirror: on while the button is held, off otherwise.
Fun fact. The Pico's internal pulls are about 50–80 kΩ — a very weak spring. A wire can easily overpower one, which is why a button only needs a direct connection to 3V3 or GND.
What you should see
The LED follows the button in real time. The console stays empty.
Common mistakes
| What you see | Why | Fix |
|---|---|---|
| The LED flickers on its own | The input is floating | Add Pin.PULL_DOWN (or PULL_UP) |
| The button works backwards | The pull does not match the wiring | Button to 3V3 → PULL_DOWN; to GND → PULL_UP |
| Nothing happens | The button straddles two different rows | Put its legs in the correct two nets |
| The board reports damage | 5 V reached a GPIO | Buttons go to 3V3, never 5 V |
Check yourself
- What does a floating input read?
- Button to 3V3: which pull do you need?
- Why is
utime.sleep_ms(10)inside the loop?
Answers: anything — it is undefined · pull-down · to sample repeatedly without starving the board.
Remember
- Inputs read a voltage; they do not drive one.
- A floating pin is undefined — always give it a pull.
PULL_DOWN+ button to 3V3 reads 0 when released, 1 when pressed.
Go further
- Add debouncing and a reaction time — Reaction game.
- Combine two buttons with a state machine — Two-way switch.