Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Micro:bit Controlled Traffic Light Simulation

View and Edit Project In Cirkit DesignerImage of Micro:bit Controlled Traffic Light Simulation

Traffic Light System Circuit Documentation

Summary

The Traffic Light System is a simple educational project that simulates a traffic light sequence using a micro:bit microcontroller and three LEDs (red, yellow, and green). The micro:bit controls the LEDs to light up in a specific order, mimicking the operation of a standard traffic light. The circuit is powered by the micro:bit, and the LEDs are connected to it via alligator clip cables.

Component List

micro:bit

LED: Two Pin (red)

LED: Two Pin (green)

LED: Two Pin (yellow)

Alligator Clip Cable (blue)

Alligator Clip Cable (red)

Alligator Clip Cable (green)

Wiring Details

micro:bit

LED: Two Pin (red)

LED: Two Pin (green)

LED: Two Pin (yellow)

Alligator Clip Cable (blue)

Alligator Clip Cable (red)

Alligator Clip Cable (green)

Documented Code

/*
 * Traffic Light System
 * This code controls a traffic light system using three LEDs (red, yellow, 
 * and green) connected to a micro:bit. The system cycles through the LEDs 
 * to simulate a traffic light sequence.
 */

// Pin definitions
const int greenLEDPin = 0; // Pin 0 for green LED
const int yellowLEDPin = 1; // Pin 1 for yellow LED
const int redLEDPin = 2; // Pin 2 for red LED

void setup() {
  // Initialize the LED pins as outputs
  pinMode(greenLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
}

void loop() {
  // Green light on for 5 seconds
  digitalWrite(greenLEDPin, HIGH);
  delay(5000);
  digitalWrite(greenLEDPin, LOW);

  // Yellow light on for 2 seconds
  digitalWrite(yellowLEDPin, HIGH);
  delay(2000);
  digitalWrite(yellowLEDPin, LOW);

  // Red light on for 5 seconds
  digitalWrite(redLEDPin, HIGH);
  delay(5000);
  digitalWrite(redLEDPin, LOW);
}

Filename: Traffic Light.ino

This code is designed to run on a micro:bit microcontroller. It sets up three pins as outputs to control the red, yellow, and green LEDs. In the main loop, it turns on each LED in sequence, with the green and red LEDs on for 5 seconds each and the yellow LED on for 2 seconds, creating a traffic light effect.