MicroPython on Raspberry Pi Pico: Blinking the Onboard LED

The Raspberry Pi Pico includes a built‑in status LED on the board.

    

MicroPython on Raspberry Pi Pico: Blinking the Onboard LED

The Raspberry Pi Pico includes a built‑in status LED on the board.
On physical hardware, this LED toggles every half‑second.


If you’re reading this without a Pico, the terminal output mirrors the LED’s state so you can follow along.


Source Code (MicroPython)

import time
from machine import Pin

led = Pin("LED", Pin.OUT)

while True:
    led.toggle()
    print("LED is now:", "ON" if led.value() else "OFF")
    time.sleep(0.5)

# pseudocode:
# configure the onboard LED using the board-agnostic "LED" alias
# loop forever:
#     toggle the LED state
#     print the current LED state to the terminal
#     wait half a second
  • Board‑safe LED setupPin("LED") works on Pico, Pico W, Pico 2, and Pico 2 W.
  • Toggle — flips the LED state directly in hardware.
  • Value readbackled.value() returns the current output state.
  • Timingtime.sleep(0.5) pauses for half a second.

Expected Output

LED is now: ON
LED is now: OFF
LED is now: ON
LED is now: OFF

Expected Physical Output

  • The onboard LED blinks at a steady 1 Hz (0.5 seconds on, 0.5 seconds off).

This pattern is the foundation of physical computing in MicroPython:
configure a pin → change its state → observe the result



Copyright © 2026 Tech-Reader.blog
All Rights Reserved

Popular posts from this blog

Insight: The Great Minimal OS Showdown—DietPi vs Raspberry Pi OS Lite

Running AI Models on Raspberry Pi 5 (8GB RAM): What Works and What Doesn't