Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
kiroloskhairy
Published

Traffic light

A road signal for directing vehicular traffic by means of colored lights, typically red for stop, green for go, and yellow for wait.

BeginnerFull instructions provided2,443
Traffic light

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Grove - 16 x 2 LCD (White on Blue)
Seeed Studio Grove - 16 x 2 LCD (White on Blue)
×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
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V battery (generic)
9V battery (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

fritzing circuit diagram for Traffic Light

simulation Traffic Light by proteus

Code

Traffic_light.ino

Arduino
int ledr = 2;
int ledy = 3;
int ledg = 4;

int i=0;

#include<LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);

byte STOP[8]={
  B00000,
  B01110,
  B10011,
  B10101,
  B11001,
  B01110,
  B00000,
  B00000

};

byte GO[8]={
  B01110,
  B01110,
  B11111,
  B10101,
  B10101,
  B01110,
  B01010,
  B01010
};

void setup() {
  pinMode(ledr,OUTPUT);
  pinMode(ledy,OUTPUT);
  pinMode(ledg,OUTPUT);

  lcd.begin(16,2);

  lcd.createChar(0,STOP);
  lcd.createChar(1,GO);
}

void loop() {
  
  //RED
  digitalWrite(ledr,HIGH);

  lcd.setCursor(4,0);
  lcd.write(byte(0));
  lcd.print(" STOP ");
  lcd.write(byte(0));
 
  for(i=0;i<11;i++)
    {lcd.setCursor(7,1);
     lcd.print(i);
     delay(1000);}


  digitalWrite(ledy,HIGH);

  lcd.setCursor(7,1);
     lcd.print("11");
  
  delay(1000);
  digitalWrite(ledy,LOW);
  
  lcd.setCursor(7,1);
     lcd.print("12");
  
  delay(1000);
  digitalWrite(ledy,HIGH);

  lcd.setCursor(7,1);
     lcd.print("13");
  
  delay(1000);
  digitalWrite(ledy,LOW);

  lcd.setCursor(7,1);
     lcd.print("14");
  
  delay(1000);
  digitalWrite(ledy,HIGH);

  lcd.setCursor(7,1);
     lcd.print("15");
  
  delay(1000);
  digitalWrite(ledy,LOW);
  digitalWrite(ledr,LOW);



  lcd.clear();
   
 //GREEN 
  digitalWrite(ledg,HIGH);

  lcd.setCursor(5,0);
  lcd.write(byte(1));  
  lcd.print(" GO ");
  lcd.write(byte(1));  

  for(i=0;i<11;i++)
    {lcd.setCursor(7,1);
     lcd.print(i);
     delay(1000);}
     
   digitalWrite(ledy,HIGH);

  lcd.setCursor(7,1);
     lcd.print("11");
  
  delay(1000);
  digitalWrite(ledy,LOW);
  
  lcd.setCursor(7,1);
     lcd.print("12");
  
  delay(1000);
  digitalWrite(ledy,HIGH);

  lcd.setCursor(7,1);
     lcd.print("13");
  
  delay(1000);
  digitalWrite(ledy,LOW);

  lcd.setCursor(7,1);
     lcd.print("14");
  
  delay(1000);
  digitalWrite(ledy,HIGH);

  lcd.setCursor(7,1);
     lcd.print("15");
  
  delay(1000);
  digitalWrite(ledy,LOW);
  digitalWrite(ledg,LOW);



  lcd.clear();
}

Credits

kiroloskhairy

kiroloskhairy

0 projects • 7 followers

Comments