Raspberry pi pico alternating led blink
Alternating LED Blink Using Raspberry Pi Pico (MicroPython)
Objective
a. blinks two LEDs (Blue and Green) in an alternating pattern
b. to control multiple GPIO pins using MicroPython.
Components Required
S.N. Component Quantity
1 Raspberry Pi Pico 1
2 Blue LED 1
3 Green LED 1
4 Breadboard + Wires As needed
5 Micro USB Cable 1
Circuit Description
The Blue LED is connected to GPIO 0.
The Green LED is connected to GPIO 1.
The other terminal of both LEDs is connected to GND.
ckt diagram:
Code: MicroPython for Alternating Blink
from machine import Pin
from time import sleep
led1 = Pin(0, Pin.OUT) # Blue LED
led2 = Pin(1, Pin.OUT) # Green LED
while True:
led1.on()
led2.off()
sleep(0.5)
led1.off()
led2.on()
sleep(0.5)
Working Principle
⦁ Pin(0, Pin.OUT) sets GPIO 0 (Blue LED) as an output.
⦁ Pin(1, Pin.OUT) sets GPIO 1 (Green LED) as an output.
⦁ Inside the loop:
⦁ First, Blue LED turns on, Green LED turns off for 0.5 seconds.
⦁ Then, Blue LED turns off, Green LED turns on for 0.5 seconds.
This process repeats endlessly, creating an alternating blink pattern.
Applications
Useful for learning GPIO control.
Can be modified for traffic light or indicator systems.
Base for LED sequence or pattern generation.
Advantages
Very simple and beginner-friendly.
No external libraries needed.
Teaches timing and pin toggling logic.
Limitations
Fixed timing without user input.
No brightness control (use PWM for that).
Only two LEDs controlled — more can be added with care.
References
Raspberry Pi Pico documentation.
MicroPython basics for GPIO.
Assistance from ChatGPT and hands-on testing.
Conclusion
This alternating LED project is a great first step in exploring Raspberry Pi Pico GPIO programming. Once comfortable, you can try adding buttons, sensors, or expand the LED count for more complex behaviors.

Comments
Post a Comment