This project focuses on a single junction traffic light system with timer and led display. The above concept can be used to develop a multi junction traffic light system.
2. Demonstration3.Circuit- 3.1 LED
A light-emitting diode(LED) is a semiconductor light source that emits light when current flows through it. The longer leg of the led is the anode(+) and the shorter leg is the cathode(-). Always connect a resistor in series with the led in order to prevent the led from burning due to high current.
- 3.2 16x2 LCD panel
- 3.3 Seven segmented LED display
- 3.4 Connections
>>For 7 segmented LED display, connect a to 2, connect b to 3, connect c to 4, connect d to 5, connect e to 6, connect f to 7 and connect g to 8. All the connection should be made with a 1k resistor in series with them. Connect the upper comm pin to 5V(common anode configuration).
>>For LCD panel, connect VSS, RW and LED(-ve) pins to GND. Connect VDD and LED(+ve) pins to +5V supply. Connect the D7 pin to 8, D6 pin to 9, D5 pin to 10, D4 pin to 11, E(Enable) pin to 12, and RS pin to 13. Also connect VEE pin to the potentiometer output(connect the potentiometer inputs to 5V and Gnd respectively).
>>Connect the anode(longer leg) of red led to A1, yellow led to A2 and green led to A3. All leds should be connected through 1k resistor. Connect the cathode(shorter leg) of all leds to Gnd.
4. Code#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;
}
}
}
Comments