Check out the Wokwi Prototype.
Don't forget to check the Pi Pico Diagram as you go:
from machine import Pin
from time import sleep
# Wait for USB to become ready
sleep(0.1)
#store desired output pin in a variable
led_pin = 25
#configure GPIO Pin as an output pin and create and led object for Pin
led = Pin(led_pin, Pin.OUT)
while True:
led.value(True) #turn on the LED
sleep(1) #wait for one second
led.value(False) #turn off the LED
sleep(1) #wait for one secondNote
The Onboard LED is connected to GPIO Pin 25 and useful for debugging events.
- The onboard LED next to the USB connection should toggle on/off every second.
| LED pin | Pi Pico pin |
|---|---|
| Long (anode) | GP15 (20) |
| Short (cathode) | Ground (GND) |
Note
Students can build using physical components or prototype using this Template Wokwi Project.
from machine import Pin
from time import sleep
# Wait for USB to become ready
sleep(0.1)
#store desired output pin in a variable
led_pin = 25
led2_pin = 15
#configure GPIO Pin as an output pin and create and led object for Pin
led = Pin(led_pin, Pin.OUT)
led2 = Pin(led2_pin, Pin.OUT)
while True:
led.value(True) #turn on the LED
led2.value(False) #turn off the LED2
sleep(1) #wait for one second
led.value(False) #turn off the LED
led2.value(True) #turn on the LED2
sleep(1) #wait for one second- The onboard LED and external LED next to the USB connection should alternatively toggle on/off every second.
A resistor is required to protect the LED from over current. To calculate the resistor value for an LED connected to a 3.3V source, you need to use Ohm's Law
- Find the LED's forward voltage (V_forward): This is the voltage drop across the LED when it's turned on. Typical values are around 2V for red/green LEDs and 3V for blue/white LEDs. If you don't know the exact forward voltage, check the LED's datasheet or consult a reference chart.
- Determine the desired forward current (I_forward): This is the current you want the LED to draw. A common range is 5mA to 20mA. You can find this information in the LED's datasheet or use a typical value.
- Calculate the resistance (R): Plug the values into the formula: R = (V_source - V_forward) / I_forward Example: Let's assume you have a 3.3V source, an LED with a forward voltage of 2V, and you want a forward current of 10mA (0.01A).
R = (3.3V - 2V) / 0.01A
R = 1.3V / 0.01A
R = 130 Ohms
You would then choose a resistor with a value close to 130 Ohms.
