Traffic Light Module with 7 Segment Display

The integration of a Traffic Light Module with a 7-Segment Display allows for the simultaneous representation of traffic light signals and numerical information. This combination offers a comprehensive visual display system, where the 7-segment display can provide additional data such as countdown timers, status indicators, or numeric values relevant to the traffic light operation. By combining these two components, users can receive both qualitative and quantitative information, enhancing the overall functionality and usability of the traffic light system.

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. Jumper wires
  7. USB cable to connect Arduino to computer
  8. Arduino Web Editor (online) or Arduino IDE software (offline)

Traffic Light Module with 7 Segment Display Breadboard Diagram

Traffic Light Module with 7 Segment Display Breadboard Diagram (Anode Configuration)

Traffic Light Module with 7 Segment Display Code (Common Anode)

In other simple code, paste the following code:

include <SevSeg.h>
SevSeg sevseg;
int red = 13;
int yellow = 12;
int green = 11;
void setup()
{
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
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); //put any number other than number 0 to 9 to present no number
sevseg.refreshDisplay();
digitalWrite(green, HIGH);
delay(15000);
digitalWrite(green, LOW);

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();
}

*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.

This project seems quite straightforward, doesn’t it? Hence, you could elevate it by incorporating supplementary components like a pedestrians push button. Exploring the interplay between push buttons within this context could expand the project’s scope into something more substantial.

Similar Posts

Leave a Reply

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