A modern technology banner image

Traffic signal with countdown, four-digit

OBJECTIVE

To determine the traffic control is managed by counting down the time for each basic traffic light signal (red, yellow, and green).

MODULES REQUIRED

  • Arduino uno
  • 4 digit display
  • Resistor 220Ω
  • Green Led
  • Red led
  • Yellow led

SCHEMATIC DIAGRAM

Schematic diagram showing an Arduino connected to an LED and a push button.

SCHEMATIC CONNECTION

Connect 4 digit display:

  • Connect the VCC pin of the 4-digit display to the 5V pin on the Arduino.
  • Connect the GND pin of the 4-digit display to the GND pin on the Arduino .
  • Connect the GND pin of the 4-digit display to the GND pin on the Arduino .
  • Connect the Di0 pin of the 4-digit display to the D3 pin on the Arduino .
  • Connect Green LED :

  • Connect the anode (+ve) of the green LED to pin D6 on the Arduino through a resistor.
  • Connect the cathode(-ve) of the green LED to GND pin of the Arduino
  • Connect Yellow LED :

  • Connect the anode (+ve) of the yellow LED to pin D5 on the Arduino through a resistor.
  • Connect the cathode(-ve) of the Yellow LED to GND pin of the Arduino
  • Connect RED LED :

  • Connect the anode (+ve) of the Red LED to pin D4 on the Arduino through a resistor.
  • Connect the cathode (-ve) of the Red LED to GND pin of the Arduino
  • To begin your project, click this template link:

    Simulate on Wokwi

    ARDUINO CODE

    
    #include (TM1637Display.h)
    
    // Define the pins for the 4-digit display (TM1637 module)
    #define CLK 2
    #define DIO 3
    
    // Create an instance of the display
    TM1637Display display(CLK, DIO);
    
    // Define pins for red, yellow, and green LEDs
    #define RED_LED 4
    #define YELLOW_LED 5
    #define GREEN_LED 6
    
    // Define the time intervals for each light
    #define GREEN_LIGHT_DURATION 5000 // 5 seconds
    #define YELLOW_LIGHT_DURATION 3000 // 3 seconds
    #define RED_LIGHT_DURATION 7000 // 7 seconds
    
    unsigned long previousMillis = 0;
    int light = 1;
    int remainingTime = 0;
    
    void setup() {
      // Set pins as OUTPUT
      pinMode(RED_LED, OUTPUT);
      pinMode(YELLOW_LED, OUTPUT);
      pinMode(GREEN_LED, OUTPUT);
      
      // Initialize the 4-digit display
      display.setBrightness(7); // Adjust the brightness (0-7)
    }
    
    void loop() {
      unsigned long currentMillis = millis();
      
      switch (light) {
        case 1: // Green light
          digitalWrite(RED_LED, LOW);
          digitalWrite(YELLOW_LED, LOW);
          digitalWrite(GREEN_LED, HIGH);
          if (remainingTime > 0) {
            if (currentMillis - previousMillis >= 1000) {
              remainingTime--;
              previousMillis = currentMillis;
            }
          } else {
            light = 2; // Switch to yellow light
            remainingTime = 3;
            previousMillis = currentMillis;
          }
          break;
        case 2: // Yellow light
          digitalWrite(RED_LED, LOW);
          digitalWrite(YELLOW_LED, HIGH);
          digitalWrite(GREEN_LED, LOW);
          if (remainingTime > 0) {
            if (currentMillis - previousMillis >= 1000) {
              remainingTime--;
              previousMillis = currentMillis;
            }
          } else {
            light = 3; // Switch to red light
            remainingTime = 7;
            previousMillis = currentMillis;
          }
          break;
        case 3: // Red light
          digitalWrite(RED_LED, HIGH);
          digitalWrite(YELLOW_LED, LOW);
          digitalWrite(GREEN_LED, LOW);
          if (remainingTime > 0) {
            if (currentMillis - previousMillis >= 1000) {
              remainingTime--;
              previousMillis = currentMillis;
            }
          } else {
            light = 1; // Switch to green light
            remainingTime = 5;
            previousMillis = currentMillis;
          }
          break;
      }
    
      // Display the remaining time on the 4-digit display
      display.showNumberDecEx(remainingTime, 0b01000000, true);
    }
    
    
    

    INSTRUCTIONS

  • Assemble the circuit by connecting all components as shown in the schematic diagram.
  • On the left side of the screen, open sketch.ino and write your Arduino code.
  • After completing the circuit and writing the code, click the green Play button to start the simulation.
  • Traffic control is managed by sequentially counting down the pre-set time for each red, yellow, and green traffic light signal.
  • WORKING PRINCIPLE

  • The working principle of the traffic light controller uses pre-programmed timers for each signal (red, yellow, green), sequentially activating each for its designated countdown duration to manage traffic flow.

  • Project Link

    for your reference.

    `