PI PICO RED YELLOW AND GREEN LIGHT

Description of the Raspberry Pi Pico Traffic Light Simulation Code

This code simulates a simple traffic light system using a Raspberry Pi Pico. It defines three pins for the traffic light colors: RED, YELLOW, and GREEN. The program initializes these pins as outputs in the setup() function.

In the loop() function, the traffic light operates in a sequence:

  1. The GREEN light is turned on for 3 seconds, indicating that vehicles can go.
  2. The GREEN light is turned off, and the YELLOW light is activated for 0.5 seconds, signaling that the light is about to change.
  3. The RED light is then turned on for 2 seconds, stopping traffic.
  4. Finally, the YELLOW light is activated for 0.5 seconds before turning off, followed by turning off the RED light.

This project is a great introduction to controlling multiple outputs with the Raspberry Pi Pico and understanding basic timing and sequences in programming.

SCHEMATIC:

CODE:

#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);

}

  • Raspberry Pi Pico projects
  • Traffic light simulation tutorial
  • GPIO pin control with Raspberry Pi Pico
  • Arduino-style programming on Pico
  • Digital output control
  • DIY electronics projects
  • LED traffic light project
  • Basic programming for beginners
  • Pico microcontroller applications
  • Electronics projects for learning

Comments