RGB LED Cycle Using Raspberry Pi Pico (MicroPython)
🔴🟢🔵 Button-Controlled RGB LED Cycle Using Raspberry Pi Pico (MicroPython)
Objective
-
To demonstrate how to use a push button to cycle through three different LEDs (Red, Green, and Blue) connected to a Raspberry Pi Pico.
-
To learn input reading, edge detection, and RGB control in MicroPython.
Components Required
| S.N. | Component | Quantity |
|---|---|---|
| 1 | Raspberry Pi Pico | 1 |
| 2 | Red LED | 1 |
| 3 | Green LED | 1 |
| 4 | Blue LED | 1 |
| 5 | Push Button | 1 |
| 6 | 220Ω Resistors | 3 (optional) |
| 7 | Breadboard + Jumper Wires | As needed |
| 8 | Micro USB Cable | 1 |
Circuit Description
-
Red LED → GPIO 2
-
Green LED → GPIO 1
-
Blue LED → GPIO 0
-
All cathodes of the LEDs go to GND through 220Ω resistors.
-
Push Button → GPIO 15, with internal pull-down resistor enabled using
Pin.PULL_DOWN.
Working Principle
The MicroPython script continuously monitors the button state. When a button press (rising edge) is detected:
-
A counter is incremented.
-
Based on the value of the counter (1 to 3), it lights up one of the LEDs:
-
1= Red -
2= Green -
3= Blue
-
-
After
3, the counter resets to1, creating a looped LED cycle. -
A debounce delay is used to avoid repeated triggering from mechanical button noise.
Code: MicroPython
Sample Output
Applications
-
RGB LED control
-
Simple color-coded feedback system
-
Learn edge detection and state transitions in embedded systems
Advantages
-
Teaches button debouncing and state machine logic
-
Scalable to add more LEDs or modes
-
Beginner-friendly GPIO and logic structure
Limitations
-
No PWM (only full ON/OFF LEDs)
-
No long-press detection
-
Button bounces handled by fixed delay (not interrupt-based)
References
-
assistance by ChatGpt
-
Compiler is thonny application
-
Practical implementation tested and verified by Kailash
Conclusion
This simple project helps you grasp GPIO input-output interactions and logic flow on Raspberry Pi Pico. Use of RGB led .

Comments
Post a Comment