Push Button Using Raspberry Pi Pico
Control LED with Push Button Using Raspberry Pi Pico (MicroPython)
Objective
To control an LED using a push button on a Raspberry Pi Pico, written in MicroPython. This project is perfect for beginners learning input and output (I/O) control on microcontrollers.
Components Required
| S.N. | Component | Quantity |
|---|---|---|
| 1 | Raspberry Pi Pico | 1 |
| 2 | LED (any color) | 1 |
| 3 | 220Ω Resistor | 1(optional) |
| 4 | Push Button | 1 |
| 5 | Breadboard + Wires | As needed |
| 6 | Micro USB Cable | 1 |
Circuit Description
-
LED's anode (long leg) is connected to GPIO 0 through a 220Ω resistor, and cathode to GND.
-
Push button is connected between GPIO 1 and 3.3V.
-
An internal pull-down resistor is enabled in code to keep the button input low when not pressed.
-
When the button is pressed, the input pin reads HIGH, and the LED turns ON.
Code: MicroPython for Button Controlled LED
Working Principle
-
Pin(0, Pin.OUT)sets GPIO 0 as an output for the LED. -
Pin(1, Pin.IN, Pin.PULL_DOWN)sets GPIO 1 as an input and activates the internal pull-down resistor.(you may used external resistor for pull up or down ) -
In the loop:
-
If the button is pressed (
button.value() == 1), the LED turns ON. -
If the button is not pressed (
button.value() == 0), the LED turns OFF.
-
-
sleep(0.001)adds a tiny delay to avoid unnecessary CPU load.
Applications
-
Basic digital input handling.
-
Foundation for building user interfaces (like switches or sensors).
-
Can be expanded into memory games, door alarms, or counters.
Advantages
-
Simple and very easy to understand.
-
Helps grasp core GPIO concepts (input/output).
-
Can be modified to include more buttons, LEDs, or logic.
Limitations
-
No software debounce (LED may flicker if button bounces).
-
Only controls one LED with one button.
-
Doesn’t store LED state after button release.
Suggestions
-
Add software debounce logic using delay or state tracking.
-
Use toggle logic to remember the state after button release.
-
Expand with multiple LEDs and buttons for more complex projects.
References
-
Raspberry Pi Pico GPIO documentation.
-
Youtube.
-
Concept explained and guided by ChatGPT.
Conclusion
This simple LED control project using a push button and Raspberry Pi Pico is an excellent way to start learning real-world input/output programming. It lays the foundation for more advanced interaction-based microcontroller projects.

Comments
Post a Comment