In this tutorial, we will learn how to control an LED of the Raspberry Pi Pico. This is the first program to test both the Pico and verify that the Thonny IDE and Micro Python are set up correctly on your system.
NOTE: If you want to use an external LED, choose any suitable GPIO pin on the Pico and update the LED pin number in the code accordingly.
Item Required:
Connections:


Code:
from machine import Pin
from time import sleep
led = Pin('LED', Pin.OUT)
print('Blinking LED Example')
while True:
led.value(not led.value())
sleep(0.5)
Plug one end of the USB cable into your laptop and the other end into the Pico.
Upload the code to the Raspberry Pi Pico using Thonny, save it as main.py, and run it by clicking the green “Play” button in Thonny.
Results:
The LED will blink ON and OFF every 0.5 seconds.