This tool will simulate how traffic light can work with 4 sides of the road. The principle is the same as the existing traffic light on the street, when the green light is lit then 3 other road segment red lights are on. After 30 seconds the green light turns off and replaces the yellow light for 5 seconds and another red light is still on. Then the red light lights up all at the same time for 3 seconds, then change the next segment that turns clockwise. Well because it is still a simulation then the pause of life and the death of lights made faster than the real
This tool is built from Arduino UNO as the main system & controller of the system. Red, yellow and green LEDs are used as a traffic light simulation. The traffic light lighs up on the set time of the program.
Hardware Requirement
- 4 LED with Red Colour
- 4 LED with Yellow Colour
- 4 LED with Green Colour
- Arduino
- Power supply +5Volt
Block diagram
H --> Green LED
K --> Yellow LED
M --> Red LED
Schematic
Arduino Uno and LED Wiring
Source Code / Sketch
void setup() {
//------------------pin 2 s/d pin 13 sebagai dig output
for(char i=2;i<14;i++){
pinMode(i, OUTPUT);
}
//------------------Matikan semua LED
for(char i=2;i<14;i++){
digitalWrite(i, 0);
}
//--------Hidupkan H1 + M2 + M3 + M4
digitalWrite(2,1);
digitalWrite(7,1);
digitalWrite(10,1);
digitalWrite(13,1);
}
void loop() {
//-------------H1 + M2 + M3 + M4 ON
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,0);
delay(5000);
//-------------K1 + M2 + M3 + M4 ON
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,0);
delay(2000);
//-------------M1 + M2 + M3 + M4 ON
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,1);
delay(1000);
//-------------M1 + H2 + M3 + M4 ON
digitalWrite(5,1);
digitalWrite(6,0);
digitalWrite(7,0);
delay(5000);
//-------------M1 + K2 + M3 + M4 ON
digitalWrite(5,0);
digitalWrite(6,1);
digitalWrite(7,0);
delay(2000);
//-------------M1 + M2 + M3 + M4 ON
digitalWrite(5,0);
digitalWrite(6,0);
digitalWrite(7,1);
delay(1000);
//-------------M1 + M2 + H3 + M4 ON
digitalWrite(8,1);
digitalWrite(9,0);
digitalWrite(10,0);
delay(5000);
//-------------M1 + M2 + K3 + M4 ON
digitalWrite(8,0);
digitalWrite(9,1);
digitalWrite(10,0);
delay(2000);
//-------------M1 + M2 + M3 + M4 ON
digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(10,1);
delay(1000);
//-------------M1 + M2 + M3 + H4 ON
digitalWrite(11,1);
digitalWrite(12,0);
digitalWrite(13,0);
delay(5000);
//-------------M1 + M2 + M3 + K4 ON
digitalWrite(11,0);
digitalWrite(12,1);
digitalWrite(13,0);
delay(2000);
//-------------M1 + M2 + M3 + M4 ON
digitalWrite(11,0);
digitalWrite(12,0);
digitalWrite(13,1);
delay(1000);
}
How it works
1. all of the red LED will light up within 1 second.
2. The green LED 1 (H1) will light up within 5 seconds.
3. and the yellow LED (K1) will light up within 2 seconds.
4. After that the system will loop so the red LED lights back on in 1 second.
5. Then it will change on the side of the 2nd lamp continuously with clockwise rotation.
Video for Project I - 1. Traffic Light Simulator (Arduino Uno Based)
Download the required file.
No comments:
Post a Comment