Pedestrian-Controlled Traffic Light equipped with a Countdown Timer

Pedestrian-Controlled Traffic Light equipped with a Countdown Timer is a type of traffic signal system that includes a button for pedestrians to request a crossing and a countdown timer that displays the remaining time before the signal changes. This article explores a straightforward project on traffic lights incorporating a 7-Segment Display and a pedestrian push button.

Materials Needed

  1. Arduino Mega 2560 R3 (or any other Arduino board)
  2. Breadboard
  3. 7 Segment Display
  4. 8 pcs Resistor 220 Ohm
  5. 3 pcs LEDs; Red, Yellow, Green with 3 Resistor; 1k Ohm (or Ready Traffic Light Module)
  6. Push Button with 220 Ohm Resistor
  7. Jumper wires
  8. USB cable to connect Arduino to computer
  9. Arduino Web Editor (online) or Arduino IDE software (offline)

Pedestrian-Controlled Traffic Light with Countdown Timer Circuit

Pedestrian-Controlled Traffic Light with Countdown Timer Breadboard Diagram

Pedestrian-Controlled Traffic Light with Countdown Timer Code

include <SevSeg.h>
SevSeg sevseg;
const int buttonPin = 14; // Pin connected to pushbutton
int red = 13;
int yellow = 12;
int green = 11;
int buttonState = 0; // Give pushbutton a value

void setup()
{
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(buttonPin, INPUT); // Set pushbutton pin as input
byte numDigits = 1;
byte digitPins[] = {};
byte segmentPins[] = {3, 2, 5, 6, 7, 8, 9, 4};
bool resistorsOnSegments = true;

byte hardwareConfig = COMMON_ANODE;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(90);
}
void loop()
{

digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(9);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(8);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(7);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(6);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(5);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(4);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(3);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(2);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(1);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(100);
sevseg.refreshDisplay();
digitalWrite(green, HIGH);
delay (10000);
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH) {// If pushbutton is pressed, set as HIGH
digitalWrite(green, HIGH);
delay(10000);

sevseg.setNumber(5);
sevseg.refreshDisplay();
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
delay(500);

sevseg.setNumber(4);
sevseg.refreshDisplay();
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
delay(500);

sevseg.setNumber(3);
sevseg.refreshDisplay();
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
delay(500);

sevseg.setNumber(2);
sevseg.refreshDisplay();
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
delay(500);

sevseg.setNumber(1);
sevseg.refreshDisplay();
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
sevseg.setNumber(10);
delay(500);

sevseg.setNumber(9);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red,  LOW);
delay(500);

sevseg.setNumber(8);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red,  LOW);
delay(500);

sevseg.setNumber(7);
sevseg.refreshDisplay();  
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(6);
sevseg.refreshDisplay();  
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(5);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(4);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(3);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(2);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

sevseg.setNumber(1);
sevseg.refreshDisplay();
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
delay(500);

}
else if (buttonState == LOW);
{// Turn on LED as usual
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
delay(500);
}

sevseg.setNumber(9);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(8);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(7);
sevseg.refreshDisplay();digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(6);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(5);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(4);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(3);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(2);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);

sevseg.setNumber(1);
sevseg.refreshDisplay();
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
sevseg.setNumber(0);
sevseg.refreshDisplay();
}

Indeed, a project like a pedestrian-controlled traffic signal with a countdown timer is quite fascinating, don’t you think? This project combines elements of urban safety, technology, and efficient traffic management. It not only serves a practical purpose but also provides an opportunity for learning about electronics, programming, and urban planning. Additionally, you could consider incorporating features like sensors for detecting pedestrian presence or optimizing the countdown timer based on traffic flow for added functionality.

*If you’re using the cathode configuration, you can replace the code with the following line: byte hardwareConfig = COMMON_CATHODE and make sure the wiring connection is in cathode configuration.

Note: make sure you include the SevSeg.h zip file in your Arduino library.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *