Adhyoksh Jyoti
Published

Traffic light with display

Come and design a traffic light system on your own!!

IntermediateFull instructions provided1 hour21,451
Traffic light with display

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
5 mm LED: Green
5 mm LED: Green
×1
Jumper wires (generic)
Jumper wires (generic)
×15
Breadboard (generic)
Breadboard (generic)
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Resistor 1k ohm
Resistor 1k ohm
×10
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Schemstics

Code

Arduino Code

Arduino
#include <LiquidCrystal.h>
LiquidCrystal mylcd(13,12,11,10,9,8);
int a=2,b=3,c=4,d=5,e=6,f=7,g=A0;
int COUNT;
int red=A1,yellow=A2,green=A3;
void setup()
{
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(a,OUTPUT);
  pinMode(b,OUTPUT);
  pinMode(c,OUTPUT);
  pinMode(d,OUTPUT);
  pinMode(e,OUTPUT);
  pinMode(f,OUTPUT);
  pinMode(g,OUTPUT);
  mylcd.begin(16,2);
  mylcd.home();
}
 
void loop()
{
 analogWrite(red,0);
 analogWrite(yellow,0);
 analogWrite(green,0);

mylcd.clear();
 analogWrite(yellow,255);
 mylcd.print("Wait");
 timer(3);           
 
 mylcd.clear();    
 analogWrite(yellow,0);
 analogWrite(red,255);
 mylcd.print("Stop");
 timer(5);
 
 mylcd.clear();
 analogWrite(red,0);
 analogWrite(yellow,255);
 mylcd.print("Wait");
 timer(3);
 
 mylcd.clear();
 analogWrite(yellow,0);
 analogWrite(green,255);
 mylcd.print("Go");
 timer(5);    
}

void timer(int nu)
 {
   for(COUNT=nu;COUNT>=0;COUNT--)
    {
      Serial.begin(9600);
      Serial.println(COUNT);
      switch (COUNT)
                {
 
                case 0://when count value is zero show”0” on disp
                digitalWrite(a, LOW);
                digitalWrite(b, LOW);
                digitalWrite(c, LOW);
                digitalWrite(d, LOW);
                digitalWrite(e, LOW);
                digitalWrite(f, LOW);
                analogWrite(g, 1);;
                delay(1000);
                break;
 
                case 1:// when count value is 1 show”1” on disp
                digitalWrite(a, HIGH);
                digitalWrite(b, LOW);
                digitalWrite(c, LOW);
                digitalWrite(d, HIGH);
                digitalWrite(e, HIGH);
                digitalWrite(f, HIGH);
                analogWrite(g, 1);
                delay(1000);
                break;
 
                case 2:// when count value is 2 show”2” on disp
                digitalWrite(a, LOW);
                digitalWrite(b, LOW);
                digitalWrite(c, HIGH);
                digitalWrite(d, LOW);
                digitalWrite(e, LOW);
                digitalWrite(f, HIGH);
                analogWrite(g, 0);
                delay(1000);
                break;
 
                case 3:// when count value is 3 show”3” on disp
                digitalWrite(a, LOW);
                digitalWrite(b, LOW);
                digitalWrite(c, LOW);
                digitalWrite(d, LOW);
                digitalWrite(e, HIGH);
                digitalWrite(f, HIGH);
                analogWrite(g, 0);
                delay(1000);
                break;
 
                case 4:// when count value is 4 show”4” on disp
                digitalWrite(a, HIGH);
                digitalWrite(b, LOW);
                digitalWrite(c, LOW);
                digitalWrite(d, HIGH);
                digitalWrite(e, HIGH);
                digitalWrite(f, LOW);
                analogWrite(g, 0);
                delay(1000);
                break;
 
                case 5:// when count value is 5 show”5” on disp
                digitalWrite(a, LOW);
                digitalWrite(b, HIGH);
                digitalWrite(c,LOW);
                digitalWrite(d, LOW);
                digitalWrite(e, HIGH);
                digitalWrite(f, LOW);
                analogWrite(g, 0);
                delay(1000);
                break; 
                }
        }                  
 }

Credits

Adhyoksh Jyoti
11 projects • 9 followers
Electronics and Communication Engineering B.Tech graduate from NIT Srinagar, J&K.

Comments