LED Button Lab
Welcome to the LED Button Lab
An LED button is a button and a light combined in one part! Press it to turn on the glow — or use code to control the light while the button waits for your touch. Let's build something amazing!
What Is an LED Button?
An LED button is a push button that has a small Light-Emitting Diode (LED) built into the cap. When the LED is on, the button glows. This makes it easy to see which button is active. You might find glowing buttons on game controllers, status panels, and interactive projects.
The Grove LED Button from Seeed Studio is a popular choice. It uses a four-pin Grove connector. Here is what each pin does:
| Pin | Signal |
|---|---|
| 1 | Button signal (HIGH when not pressed, LOW when pressed) |
| 2 | LED signal (HIGH to turn LED on) |
| 3 | GND (ground — the negative connection) |
| 4 | VCC (power — 3.3 V) |
You can also use any push button paired with a separate LED. The wiring and code are the same.
Parts You Need
| Part | Quantity | Approximate Cost |
|---|---|---|
| Raspberry Pi Pico | 1 | $4 |
| Grove LED Button (or button + LED) | 1 | $2–$3 |
| Solderless breadboard | 1 | $3 |
| Jumper wires | 4 | — |
| 330 Ω resistor (if using separate LED) | 1 | <$1 |
Wiring Steps
- Connect VCC on the button to 3.3 V (pin 36) on the Pico.
- Connect GND on the button to any GND pin on the Pico.
- Connect the button signal wire to GP14 on the Pico.
- Connect the LED signal wire to GP15 on the Pico.
Watch Out!
If you use a separate LED instead of a Grove button, always put a 330 Ω resistor in series with the LED. Without a resistor, too much current flows and the LED burns out instantly.
Sample Program: Button Toggles LED
This program turns the LED on when you press the button. Press it again and the LED turns off.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
What Each Line Does
| Line | Purpose |
|---|---|
from machine import Pin |
Loads the Pin tool so we can control hardware pins |
Pin(14, Pin.IN, Pin.PULL_UP) |
Sets GP14 as an input with the built-in pull-up resistor turned on |
Pin(15, Pin.OUT) |
Sets GP15 as an output so we can turn the LED on and off |
led_state = False |
Tracks whether the LED is on or off |
button.value() == 0 |
True when the button is pressed (the pin drops to 0) |
not led_state |
Flips True to False, or False to True |
time.sleep(0.3) |
Waits 300 ms so one press equals one toggle, not many quick ones |
Key Idea
Pin.PULL_UP turns on a tiny resistor inside the Pico. That resistor keeps the pin HIGH when the button is not pressed. When you press the button, it connects the pin to GND, so the pin drops LOW. That drop is how the Pico detects a press.
Sample Program: LED Stays On While Button Is Held
This simpler version lights the LED only while you hold the button down:
1 2 3 4 5 6 7 8 9 10 11 12 | |
What Each Line Does
| Line | Purpose |
|---|---|
button.value() == 0 |
Checks if the button is being pressed right now |
led.value(1) |
Turns the LED on |
led.value(0) |
Turns the LED off |
time.sleep(0.02) |
Waits 20 ms before checking again |
Monty's Tip
Try connecting the LED to a Pulse Width Modulation (PWM) pin and fading it in slowly when you press the button. Use PWM(Pin(15)) and duty_u16() to control brightness!
Great Work!
You wired up an LED button and controlled it two different ways. Next, try the 7-segment display to show numbers with code!