Traffic Lights With Pedestrian Crossing
by 936188 in Circuits > Arduino
1507 Views, 2 Favorites, 0 Comments
Traffic Lights With Pedestrian Crossing
This project is enhancements to the traditional Traffic lights and Pedestrian crossings such as the replacement of the pushbuttons to using a PIR motion sensor, a buzzer to signal the start of the Pedestrian crossing for pedestrians and a 7 segment display to display the count down of the pedestrian crossing.
Component
- 1 Arduino Uno R3
- 3 Red LED
- 3 Green LED
- 2 Yellow LED
- 9 400 Ω Resistor
- 1 Piezo
- 1 PIR Sensor
- 1 Cathode 7 Segment Display
- 6 300 Ω Resistor
- 1 Breadboard Small
Instruction
Demonstration
Downloads
Code
int LED_RED1 = 2; //Traffic Light 1 int LED_YELLOW1 = 3; int LED_GREEN1 = 4; int LED_RED2 = 5; //Traffic Light 2 int LED_YELLOW2 = 6; int LED_GREEN2 = 7; int LED_RED3 = 8; //Pedestrian Crossing Light int LED_GREEN3 = 9; //Pedestrian Crossing Light int sensor = 10; // The pin that the sensor is attached int state = LOW; // By default, no motion detected int val = LOW; // Variable to store the sensor status int timer = 10000; unsigned const int a = 14; unsigned const int b = 15; unsigned const int c = 16; unsigned const int d = 17; unsigned const int e = 11; unsigned const int f = 12; unsigned const int g = 13; int COUNT; int DELAY_GREEN = 5000; int DELAY_RED = 5000; int DELAY_YELLOW = 2500; void setup() { pinMode(2, OUTPUT); // Traffic Light 1 (RED) pinMode(3, OUTPUT); // Traffic Light 1 (YELLOW) pinMode(4, OUTPUT); // Traffic Light 1 (GREEN) pinMode(5, OUTPUT); // Traffic Light 1 (RED) pinMode(6, OUTPUT); // Traffic Light 1 (YELLOW) pinMode(7, OUTPUT); // Traffic Light 1 (GREEN) pinMode(8, OUTPUT); // Pedestrian Crossing Light(RED) pinMode(9, OUTPUT); // Pedestrian Crossing Light(GREEN) pinMode(LED_GREEN3, OUTPUT); Serial.begin(9600); pinMode(timer,OUTPUT); pinMode(a, OUTPUT); pinMode(b, OUTPUT); pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT); analogReference (DEFAULT); pinMode(sensor, OUTPUT); digitalWrite(sensor, LOW); delayMicroseconds(2); digitalWrite(sensor, HIGH); delayMicroseconds(5); digitalWrite(sensor, LOW); pinMode(sensor, INPUT); } void loop() { if(digitalRead(sensor) == HIGH){ delay(15); if (digitalRead(sensor) == HIGH){ state == HIGH; //Motion Detected changeLights();// function calling delay(1000); // wait 10 seconds before changing } } if (digitalRead(sensor) == LOW){ delay(15); if (digitalRead(sensor) == LOW){ state == LOW; // no motion detected // FUNCTION CALLING green_light(); delay(DELAY_GREEN); yellow_light(); delay(DELAY_YELLOW); red_light(); delay(DELAY_RED); } } } void display() { delay(500); digitalWrite(LED_GREEN3, HIGH); //9 digitalWrite(14, HIGH); //a digitalWrite(15, HIGH); //b digitalWrite(16, HIGH); //c digitalWrite(17, LOW); //d digitalWrite(11, LOW); //e digitalWrite(12, HIGH); //f digitalWrite(13, HIGH); //g delay(500); //8 digitalWrite(14, HIGH); //a digitalWrite(15, HIGH); //b digitalWrite(16, HIGH); //c digitalWrite(17, HIGH); //d digitalWrite(11, HIGH); //e digitalWrite(12, HIGH); //f digitalWrite(13, HIGH); //g delay(500); //7 digitalWrite(14, HIGH); //a digitalWrite(15, HIGH); //b digitalWrite(16, HIGH); //c digitalWrite(17, LOW); //d digitalWrite(11, LOW); //e digitalWrite(12, LOW); //f digitalWrite(13, LOW); //g delay(500); //6 digitalWrite(14, HIGH); //a digitalWrite(15, LOW); //b digitalWrite(16, HIGH); //c digitalWrite(17, HIGH); //d digitalWrite(11, HIGH); //e digitalWrite(12, HIGH); //f digitalWrite(13, HIGH); //g delay(500); //5 digitalWrite(14, HIGH); //a digitalWrite(15, LOW); //b digitalWrite(16, HIGH); //c digitalWrite(17, HIGH); //d digitalWrite(11, LOW); //e digitalWrite(12, HIGH); //f digitalWrite(13, HIGH); //g delay(500); //4 digitalWrite(14, LOW); //a digitalWrite(15, HIGH); //b digitalWrite(16, HIGH); //c digitalWrite(17, LOW); //d digitalWrite(11, LOW); //e digitalWrite(12, HIGH); //f digitalWrite(13, HIGH); //g delay(500); //3 digitalWrite(14, HIGH); //a digitalWrite(15, HIGH); //b digitalWrite(16, HIGH); //c digitalWrite(17, HIGH); //d digitalWrite(11, LOW); //e digitalWrite(12, LOW); //f digitalWrite(13, HIGH); //g delay(500); //2 digitalWrite(14, HIGH); //a digitalWrite(15, HIGH); //b digitalWrite(16, LOW); //c digitalWrite(17, HIGH); //d digitalWrite(11, HIGH); //e digitalWrite(12, LOW); //f digitalWrite(13, HIGH); //g delay(500); //1 digitalWrite(14, LOW); //a digitalWrite(15, HIGH); //b digitalWrite(16, HIGH); //c digitalWrite(17, LOW); //d digitalWrite(11, LOW); //e digitalWrite(12, LOW); //f digitalWrite(13, LOW); //g delay(500); //0 digitalWrite(14, HIGH); //a digitalWrite(15, HIGH); //b digitalWrite(16, HIGH); //c digitalWrite(17, HIGH); //d digitalWrite(11, HIGH); //e digitalWrite(12, HIGH); //f digitalWrite(13, LOW); //g delay(500); //off digitalWrite(14, LOW); //a digitalWrite(15, LOW); //b digitalWrite(16, LOW); //c digitalWrite(17, LOW); //d digitalWrite(11, LOW); //e digitalWrite(12, LOW); //f digitalWrite(13, LOW); //g digitalWrite(LED_GREEN3, LOW); delay(500); } void changeLights() { //turn off TL 1&2 yellow, then turn on PL red for 5 seconds //TL 1&2 Green + PL Green is off based off previous part digitalWrite(LED_YELLOW1, LOW); // TL 1 yellow off digitalWrite(LED_YELLOW2, LOW); // TL 2 yellow off digitalWrite(LED_RED1, HIGH); // TL1 red on digitalWrite(LED_RED2, HIGH); // TL2 red on digitalWrite(LED_RED3, HIGH); // PL red on digitalWrite(LED_GREEN3, HIGH); // PL Green on digitalWrite(LED_GREEN2, LOW); // TL 2 Green off digitalWrite(LED_GREEN1, LOW); // TL1 Green off delay(1000); digitalWrite(LED_YELLOW1, LOW); // TL 1 yellow digitalWrite(LED_YELLOW2, LOW); // TL 2 yellow digitalWrite(LED_RED1, HIGH); // TL1 red digitalWrite(LED_RED2, HIGH); // TL2 red digitalWrite(LED_RED3, LOW); // PL red digitalWrite(LED_GREEN3, LOW); // PL Green digitalWrite(LED_GREEN2, LOW); // TL 2 Green digitalWrite(LED_GREEN1, LOW); // TL1 Green delay(1000); display(); // 7 segment count down from 9 to 0 delay(100); } void green_light() { // digitalWrite(LED_GREEN1,HIGH); digitalWrite(LED_RED1,LOW); digitalWrite(LED_YELLOW1, LOW); digitalWrite(LED_GREEN2, HIGH); digitalWrite(LED_RED2, LOW); digitalWrite(LED_YELLOW2, LOW); digitalWrite(LED_GREEN3, LOW); digitalWrite(LED_RED3, HIGH); } void yellow_light() { // digitalWrite(LED_GREEN1,LOW); digitalWrite(LED_RED1,LOW); digitalWrite(LED_YELLOW1, HIGH); digitalWrite(LED_GREEN2, LOW); digitalWrite(LED_RED2, LOW); digitalWrite(LED_YELLOW2, HIGH); digitalWrite(LED_GREEN3, LOW); digitalWrite(LED_RED3, HIGH); } void red_light() { digitalWrite(LED_GREEN1,LOW); digitalWrite(LED_RED1,HIGH); digitalWrite(LED_YELLOW1, LOW); digitalWrite(LED_GREEN2, LOW); digitalWrite(LED_RED2, HIGH); digitalWrite(LED_YELLOW2, LOW); digitalWrite(LED_GREEN3, LOW); digitalWrite(LED_RED3, HIGH); }