Arduino : Advanced Traffic Light Controller

 

Arduino Advanced Traffic Light Controller:

Objective: Create a traffic light controller that mimics the behavior of a real traffic light, including pedestrian signals.

Components:

  1. Arduino board (e.g., Arduino Uno)
  2. Red, yellow, green LEDs for traffic lights
  3. Red, green LEDs for pedestrian signals
  4. Pushbuttons for pedestrian crossing request
  5. Resistors (220 ohms for LEDs, pull-down resistor for pushbuttons)
  6. Breadboard and jumper wires

Circuit:

  • Connect the LEDs for traffic lights and pedestrian signals to the appropriate digital pins on the Arduino using resistors.
  • Connect pushbuttons for pedestrian crossing requests to digital pins with pull-down resistors.

Code:

// Traffic Light Controller with Pedestrian Signals

const int trafficRed = 2;
const int trafficYellow = 3;
const int trafficGreen = 4;
const int pedestrianRed = 5;
const int pedestrianGreen = 6;
const int pedestrianButton = 7;

void setup() {
  pinMode(trafficRed, OUTPUT);
  pinMode(trafficYellow, OUTPUT);
  pinMode(trafficGreen, OUTPUT);
  pinMode(pedestrianRed, OUTPUT);
  pinMode(pedestrianGreen, OUTPUT);
  pinMode(pedestrianButton, INPUT_PULLUP);
}

void loop() {
  // Traffic Light Sequence
  digitalWrite(trafficRed, HIGH);
  digitalWrite(trafficYellow, LOW);
  digitalWrite(trafficGreen, LOW);
  delay(5000);

  digitalWrite(trafficRed, LOW);
  digitalWrite(trafficYellow, HIGH);
  delay(2000);

  digitalWrite(trafficYellow, LOW);
  digitalWrite(trafficGreen, HIGH);
  delay(5000);

  // Pedestrian Signal
  if (digitalRead(pedestrianButton) == LOW) {
    digitalWrite(trafficGreen, LOW);
    digitalWrite(trafficYellow, HIGH);
    delay(2000);

    digitalWrite(trafficYellow, LOW);
    digitalWrite(trafficRed, HIGH);
    delay(2000);

    digitalWrite(pedestrianGreen, HIGH);
    delay(5000);

    digitalWrite(pedestrianGreen, LOW);
    digitalWrite(pedestrianRed, HIGH);
    delay(2000);
    
    digitalWrite(trafficRed, LOW);
    digitalWrite(trafficGreen, HIGH);
  }
}


Explanation:

  • The traffic lights follow a standard sequence: Red (5 seconds) -> Yellow (2 seconds) -> Green (5 seconds).
  • If the pedestrian button is pressed, it interrupts the traffic light sequence, allowing pedestrians to cross: Yellow (2 seconds) -> Red (2 seconds) -> Pedestrian Green (5 seconds) -> Pedestrian Red (2 seconds) -> Resumes traffic light sequence.

Note: Ensure that you connect the components properly, and adjust the pin numbers in the code based on your wiring. Additionally, consider adding features like countdown timers, audible signals, or optimizing the code for more realism.


Comments

Popular posts from this blog

How does P10 Led Panel Work? | Working Principle and calculations

How to Drive DHT sensor without Library

Working Principle of DHT Sensors and Analysis with Logic Analyzer