Components and supplies
Resistor 220 ohm
5 mm LED: Yellow
Arduino UNO
Jumper wires (generic)
Solderless Breadboard Half Size
5 mm LED: Green
5 mm LED: Red
Apps and platforms
Arduino IDE
Project description
Code
Traffic_Lights.ino
arduino
1// declare pins 2int green1 = 8; 3int green2 = 13; 4int yellow1 = 9; 5int yellow2 = 12; 6int red1 = 10; 7int red2 = 11; 8 9 10void setup() { 11// sets pins as output 12 pinMode(green1, OUTPUT); 13 pinMode(green2, OUTPUT); 14 pinMode(yellow1, OUTPUT); 15 pinMode(yellow2, OUTPUT); 16 pinMode(red1, OUTPUT); 17 pinMode(red2, OUTPUT); 18} 19 20void loop() { 21// here you can change which lights turn on when and for how long 22 23 // green2 ON, red1 ON 24 digitalWrite(green1, LOW); 25 digitalWrite(green2, HIGH); 26 digitalWrite(yellow1, LOW); 27 digitalWrite(yellow2, LOW); 28 digitalWrite(red1, HIGH); 29 digitalWrite(red2, LOW); 30 delay(5000); 31 // green2 ON, yellow2 ON, red1 ON 32 digitalWrite(green1, LOW); 33 digitalWrite(green2, HIGH); 34 digitalWrite(yellow1, LOW); 35 digitalWrite(yellow2, HIGH); 36 digitalWrite(red1, HIGH); 37 digitalWrite(red2, LOW); 38 delay(1000); 39 // yellow2 ON, red1 ON 40 digitalWrite(green1, LOW); 41 digitalWrite(green2, LOW); 42 digitalWrite(yellow1, LOW); 43 digitalWrite(yellow2, HIGH); 44 digitalWrite(red1, HIGH); 45 digitalWrite(red2, LOW); 46 delay(2000); 47 // red1 ON, red2 ON 48 digitalWrite(green1, LOW); 49 digitalWrite(green2, LOW); 50 digitalWrite(yellow1, LOW); 51 digitalWrite(yellow2, LOW); 52 digitalWrite(red1, HIGH); 53 digitalWrite(red2, HIGH); 54 delay(2000); 55 //green1 ON, red2 ON 56 digitalWrite(green1, HIGH); 57 digitalWrite(green2, LOW); 58 digitalWrite(yellow1, LOW); 59 digitalWrite(yellow2, LOW); 60 digitalWrite(red1, LOW); 61 digitalWrite(red2, HIGH); 62 delay(5000); 63 // green1 ON, yellow1 ON, red2 ON 64 digitalWrite(green1, HIGH); 65 digitalWrite(green2, LOW); 66 digitalWrite(yellow1, HIGH); 67 digitalWrite(yellow2, LOW); 68 digitalWrite(red1, LOW); 69 digitalWrite(red2, HIGH); 70 delay(1000); 71 // yellow1 ON, red2 ON 72 digitalWrite(green1, LOW); 73 digitalWrite(green2, LOW); 74 digitalWrite(yellow1, HIGH); 75 digitalWrite(yellow2, LOW); 76 digitalWrite(red1, LOW); 77 digitalWrite(red2, HIGH); 78 delay(2000); 79 // red1 ON, red2 ON 80 digitalWrite(green1, LOW); 81 digitalWrite(green2, LOW); 82 digitalWrite(yellow1, LOW); 83 digitalWrite(yellow2, LOW); 84 digitalWrite(red1, HIGH); 85 digitalWrite(red2, HIGH); 86 delay(2000); 87} 88
Traffic_Lights.ino
arduino
1// declare pins 2int green1 = 8; 3int green2 = 13; 4int yellow1 = 9; 5int yellow2 = 12; 6int red1 = 10; 7int red2 = 11; 8 9 10void setup() { 11// sets pins as output 12 pinMode(green1, OUTPUT); 13 pinMode(green2, OUTPUT); 14 pinMode(yellow1, OUTPUT); 15 pinMode(yellow2, OUTPUT); 16 pinMode(red1, OUTPUT); 17 pinMode(red2, OUTPUT); 18} 19 20void loop() { 21// here you can change which lights turn on when and for how long 22 23 // green2 ON, red1 ON 24 digitalWrite(green1, LOW); 25 digitalWrite(green2, HIGH); 26 digitalWrite(yellow1, LOW); 27 digitalWrite(yellow2, LOW); 28 digitalWrite(red1, HIGH); 29 digitalWrite(red2, LOW); 30 delay(5000); 31 // green2 ON, yellow2 ON, red1 ON 32 digitalWrite(green1, LOW); 33 digitalWrite(green2, HIGH); 34 digitalWrite(yellow1, LOW); 35 digitalWrite(yellow2, HIGH); 36 digitalWrite(red1, HIGH); 37 digitalWrite(red2, LOW); 38 delay(1000); 39 // yellow2 ON, red1 ON 40 digitalWrite(green1, LOW); 41 digitalWrite(green2, LOW); 42 digitalWrite(yellow1, LOW); 43 digitalWrite(yellow2, HIGH); 44 digitalWrite(red1, HIGH); 45 digitalWrite(red2, LOW); 46 delay(2000); 47 // red1 ON, red2 ON 48 digitalWrite(green1, LOW); 49 digitalWrite(green2, LOW); 50 digitalWrite(yellow1, LOW); 51 digitalWrite(yellow2, LOW); 52 digitalWrite(red1, HIGH); 53 digitalWrite(red2, HIGH); 54 delay(2000); 55 //green1 ON, red2 ON 56 digitalWrite(green1, HIGH); 57 digitalWrite(green2, LOW); 58 digitalWrite(yellow1, LOW); 59 digitalWrite(yellow2, LOW); 60 digitalWrite(red1, LOW); 61 digitalWrite(red2, HIGH); 62 delay(5000); 63 // green1 ON, yellow1 ON, red2 ON 64 digitalWrite(green1, HIGH); 65 digitalWrite(green2, LOW); 66 digitalWrite(yellow1, HIGH); 67 digitalWrite(yellow2, LOW); 68 digitalWrite(red1, LOW); 69 digitalWrite(red2, HIGH); 70 delay(1000); 71 // yellow1 ON, red2 ON 72 digitalWrite(green1, LOW); 73 digitalWrite(green2, LOW); 74 digitalWrite(yellow1, HIGH); 75 digitalWrite(yellow2, LOW); 76 digitalWrite(red1, LOW); 77 digitalWrite(red2, HIGH); 78 delay(2000); 79 // red1 ON, red2 ON 80 digitalWrite(green1, LOW); 81 digitalWrite(green2, LOW); 82 digitalWrite(yellow1, LOW); 83 digitalWrite(yellow2, LOW); 84 digitalWrite(red1, HIGH); 85 digitalWrite(red2, HIGH); 86 delay(2000); 87} 88
Synchronized Traffic Lights
arduino
Synchronized Traffic Lights
1// declare pins 2int green1 = 8; 3int green2 = 13; 4int yellow1 = 9; 5int yellow2 = 12; 6int red1 = 10; 7int red2 = 11; 8 9 10void setup() { 11// sets pins as output 12 pinMode(green1, OUTPUT); 13 pinMode(green2, OUTPUT); 14 pinMode(yellow1, OUTPUT); 15 pinMode(yellow2, OUTPUT); 16 pinMode(red1, OUTPUT); 17 pinMode(red2, OUTPUT); 18} 19 20void loop() { 21// here you can change which lights turn on when and for how long 22 23 // green2 ON, red1 ON 24 digitalWrite(green1, LOW); 25 digitalWrite(green2, HIGH); 26 digitalWrite(yellow1, LOW); 27 digitalWrite(yellow2, LOW); 28 digitalWrite(red1, HIGH); 29 digitalWrite(red2, LOW); 30 delay(5000); 31 // green2 ON, yellow2 ON, red1 ON 32 digitalWrite(green1, LOW); 33 digitalWrite(green2, HIGH); 34 digitalWrite(yellow1, LOW); 35 digitalWrite(yellow2, HIGH); 36 digitalWrite(red1, HIGH); 37 digitalWrite(red2, LOW); 38 delay(1000); 39 // yellow2 ON, red1 ON 40 digitalWrite(green1, LOW); 41 digitalWrite(green2, LOW); 42 digitalWrite(yellow1, LOW); 43 digitalWrite(yellow2, HIGH); 44 digitalWrite(red1, HIGH); 45 digitalWrite(red2, LOW); 46 delay(2000); 47 // red1 ON, red2 ON 48 digitalWrite(green1, LOW); 49 digitalWrite(green2, LOW); 50 digitalWrite(yellow1, LOW); 51 digitalWrite(yellow2, LOW); 52 digitalWrite(red1, HIGH); 53 digitalWrite(red2, HIGH); 54 delay(2000); 55 //green1 ON, red2 ON 56 digitalWrite(green1, HIGH); 57 digitalWrite(green2, LOW); 58 digitalWrite(yellow1, LOW); 59 digitalWrite(yellow2, LOW); 60 digitalWrite(red1, LOW); 61 digitalWrite(red2, HIGH); 62 delay(5000); 63 // green1 ON, yellow1 ON, red2 ON 64 digitalWrite(green1, HIGH); 65 digitalWrite(green2, LOW); 66 digitalWrite(yellow1, HIGH); 67 digitalWrite(yellow2, LOW); 68 digitalWrite(red1, LOW); 69 digitalWrite(red2, HIGH); 70 delay(1000); 71 // yellow1 ON, red2 ON 72 digitalWrite(green1, LOW); 73 digitalWrite(green2, LOW); 74 digitalWrite(yellow1, HIGH); 75 digitalWrite(yellow2, LOW); 76 digitalWrite(red1, LOW); 77 digitalWrite(red2, HIGH); 78 delay(2000); 79 // red1 ON, red2 ON 80 digitalWrite(green1, LOW); 81 digitalWrite(green2, LOW); 82 digitalWrite(yellow1, LOW); 83 digitalWrite(yellow2, LOW); 84 digitalWrite(red1, HIGH); 85 digitalWrite(red2, HIGH); 86 delay(2000); 87}
Downloadable files
Sync_Traffic_Lights
Synchronized Traffic Lights
Sync_Traffic_Lights
Sync_Traffic_Lights
Synchronized Traffic Lights
Sync_Traffic_Lights
Comments
Only logged in users can leave comments