In this project, we will learn how to create a traffic light system using a Raspberry Pi Pico. It’s a fairly simple project, but it helps to better understand how to operate LEDs sequentially, as well as how to manage delays to observe the LEDs lighting up…

Necessary Materials

Here’s the necessary equipment for the project:

  • A Raspberry Pi Pico

  • 3 LEDs (red, orange, green)

  • 6 jumper wires

Here’s the circuit for your traffic light system on the Raspberry Pi Pico:

#define RED 1
#define YELLOW 5
#define GREEN 9

void setup() {
  pinMode(RED, OUTPUT);
  pinMode(YELLOW, OUTPUT);
  pinMode(GREEN, OUTPUT);
}

void loop() {
  digitalWrite(GREEN, HIGH);
  delay(3000);

  digitalWrite(GREEN, LOW);
  digitalWrite(YELLOW, HIGH);
  delay(500);

  digitalWrite(YELLOW, LOW);
  digitalWrite(RED, HIGH);
  delay(2000);

  digitalWrite(YELLOW, HIGH);
  delay(500);
  digitalWrite(YELLOW, LOW);
  digitalWrite(RED, LOW);
}