Traffic Light LEDs using Array

Jun 2026

Introduction

In this LED example, we are creating a traffic light sequence, but instead of
Here is a wiring diagram for the LED setup. This is what we will use when we run the software below.
We have wired the LEDs to GPIO pins 2, 6 & 10. These are the GPIO Pin numbers, not the actual Pi Pico Pin numbers.
Below is the software being used to drive the LEDs

#Traffic light LEDs using an array from machine import Pin import time # Define GPIO pins for the LEDs RED = Pin(2, Pin.OUT) AMBER = Pin(6, Pin.OUT) GREEN = Pin(10, Pin.OUT) # Put them in an array lights = [RED, AMBER, GREEN] # Helper function to turn all lights off def all_off(): for light in lights: light.off() while True: # Red all_off() RED.on() time.sleep(3) # Red + Amber AMBER.on() time.sleep(1) # Green all_off() GREEN.on() time.sleep(3) # Amber all_off() AMBER.on() time.sleep(1)

The software works by performing the following tasks.

Import Libraries (Machine and Time)

* Set GPIO Pins to output

Start a loop that will loop 5 times

Turn on the first LED and turn off all other LEDs

Turn on the second LED and turn off all other LEDs

Turn on the third LED and turn off all other LEDs

That's it. Pretty simple. Remember, you can control other devices using the GPIO pins other than LEDs, but the current output is limited to around 20mA. If you try to pull more than this, you could damage that GPIO Pin.