2-Way Intersection with Pedestrian Walk Cycle
Pedestrian walk cycle will only occur when both lights are red AND button has been pressed.
Components and supplies
Pushbutton switch 12mm
Resistor 1k ohm
Arduino UNO
Resistor 10k ohm
Resistor 221 ohm
LED (generic)
Project description
Code
Two-Way Intersection with Intellegent Pedestrian Walk Cycle
arduino
Two-Way traffic system (USA) that has a MAIN and an AUXILLARY lighting circuit. Once the Walk button is pressed, the program waits till both circuits return to RED before performing a WALK/DON"T WALK cycle. A software reset guarantees that MAIN will get the green light first after Walk Cycle completes.
1/* 2017 Falcom Digital Imaging L.L.C. for 2 Dean Institute of Technology PLC Class Use 3 4 Setup Variables for Walk Cycle Components. 5 You use "const int" if you want to reference a value by name - 6 you use it just like any ordinary int, but you cannot change the value. 7 This does not use any RAM.*/ 8int WalkRequest = 0; // Variable used to store the state of the Walk Push Button 9const int WalkButton = 2; 10const int RedPedLED = 6; 11const int WhitePedLED = 7; 12 13// Setup Variables for Station 1 Traffic Light Components 14const int Red1LED = 8; 15const int Yellow1LED = 9; 16const int Green1LED = 10; 17 18// Setup Variables for Station 2 Traffic Light Components 19const int Red2LED = 11; 20const int Yellow2LED = 12; 21const int Green2LED = 13; 22 23// variables that will change: 24volatile int buttonState = 0; // variable for monitoring the pushbutton status. 25/* A variable should be declared volatile whenever its value can be changed 26 by something beyond the control of the code section in which it appears, 27 such as a concurrently executing thread. 28 In the Arduino, the only place that this is likely to occur is in sections 29 of code associated with interrupts, called an interrupt service routine (ISR) */ 30 31 32 33 34void setup() { 35 pinMode(RedPedLED, OUTPUT); // Sets all LED's as OUTPUT 36 pinMode(WhitePedLED, OUTPUT); 37 pinMode(Red1LED, OUTPUT); 38 pinMode(Yellow1LED, OUTPUT); 39 pinMode(Green1LED, OUTPUT); 40 pinMode(Red2LED, OUTPUT); 41 pinMode(Yellow2LED, OUTPUT); 42 pinMode(Green2LED, OUTPUT); 43 pinMode(WalkButton, INPUT); // Sets Push Button as INPUT 44 45 attachInterrupt(0, pin_ISR, CHANGE); // "Watches" in the background for a button press 46 /* Attach an interrupt to the ISR vector to monitor Push Button. 47 Number 0 (for digital pin 2) or number 1 (for digital pin 3) are used. 48 Interrupts are useful for making things happen automatically in 49 microcontroller programs,and can help solve timing problems. 50 Good tasks for using an interrupt may include reading 51 a rotary encoder, or monitoring user input */ 52 53 // Set Initial state of all red LED to HIGH 54 digitalWrite (Red1LED, HIGH); 55 digitalWrite (Red2LED, HIGH); 56 digitalWrite (RedPedLED, HIGH); 57} 58 59 60 61 62void loop() { 63 // put your main code here, to run repeatedly: 64 65 // Station 1 Timing 66 delay(2500); // 2.5 Seconds of Red 67 digitalWrite(Red1LED, LOW); // Sets Red1 OFF Green ON 68 digitalWrite(Green1LED, HIGH); 69 delay(15000); // 15 Seconds of Green 70 digitalWrite(Green1LED, LOW); // Sets Green1 OFF Yellow ON 71 digitalWrite(Yellow1LED, HIGH); 72 delay(3500); // 3.5 Seconds of Yellow 73 digitalWrite(Yellow1LED, LOW); // Sets Yellow1 OFF Red ON 74 digitalWrite(Red1LED, HIGH); 75 76 if (WalkRequest == 1) { // If the button has been pressed 77 WalkCycle(); // Exit main loop and run WalkCycle () function 78 } 79 80 81 82 // Station 2 Timing 83 delay(2500); // 2.5 Seconds of Red 84 digitalWrite(Red2LED, LOW); digitalWrite(Green2LED, HIGH); // Sets Red2 OFF Green ON 85 delay(15000); // 15 Seconds of Green 86 digitalWrite(Green2LED, LOW); digitalWrite(Yellow2LED, HIGH); // Sets Green2 OFF Yellow ON 87 delay(3500); // 3.5 Seconds of Yellow 88 digitalWrite(Yellow2LED, LOW); digitalWrite(Red2LED, HIGH); // Sets Yellow2 OFF Red ON 89 90 if (WalkRequest == 1) { // If the button has been pressed 91 WalkCycle(); // Exit main loop and run WalkCycle () function 92 } 93} 94 95 96 97void WalkCycle() { 98 delay(3500); // 3.5 Second delay before "WALK" begins 99 digitalWrite (WhitePedLED, HIGH); digitalWrite (RedPedLED, LOW); // Turn on White Pedestrian Light 100 delay (15000); // 15 Second delay to allow crossing street 101 digitalWrite (WhitePedLED, LOW); digitalWrite(WalkButton, LOW); // Turn off White Pedestrian Light 102 delay(250); 103 for (int x = 0; x < 5; x++) { // Flash White Ped LED 5X 104 digitalWrite(WhitePedLED, HIGH); 105 delay(250); 106 digitalWrite(WhitePedLED, LOW); 107 delay(250); 108 } 109 digitalWrite(RedPedLED, HIGH); 110 WalkRequest = 0; // Reset Push Button 111 asm volatile (" jmp 0"); // Soft-reset of sketch. Makes sure Station 1 "MAIN" always gets Green after a walk cycle 112} 113 114 115 116 117void pin_ISR() { 118 buttonState = digitalRead(WalkButton); 119 (WalkRequest = 1); // Walk button has been pressed 120 // digitalWrite(WhitePedLED, buttonState); // Test Light for Interrupt use only during testing! 121}
Two-Way Intersection with Intellegent Pedestrian Walk Cycle
arduino
Two-Way traffic system (USA) that has a MAIN and an AUXILLARY lighting circuit. Once the Walk button is pressed, the program waits till both circuits return to RED before performing a WALK/DON"T WALK cycle. A software reset guarantees that MAIN will get the green light first after Walk Cycle completes.
1/* 2017 Falcom Digital Imaging L.L.C. for 2 Dean Institute of Technology 3 PLC Class Use 4 5 Setup Variables for Walk Cycle Components. 6 You use 7 "const int" if you want to reference a value by name - 8 you use it just like 9 any ordinary int, but you cannot change the value. 10 This does not use any RAM.*/ 11int 12 WalkRequest = 0; // Variable used to store the state of the Walk Push Button 13const 14 int WalkButton = 2; 15const int RedPedLED = 6; 16const int WhitePedLED = 7; 17 18// 19 Setup Variables for Station 1 Traffic Light Components 20const int Red1LED = 21 8; 22const int Yellow1LED = 9; 23const int Green1LED = 10; 24 25// Setup Variables 26 for Station 2 Traffic Light Components 27const int Red2LED = 11; 28const int Yellow2LED 29 = 12; 30const int Green2LED = 13; 31 32// variables that will change: 33volatile 34 int buttonState = 0; // variable for monitoring the pushbutton status. 35/* A 36 variable should be declared volatile whenever its value can be changed 37 by something 38 beyond the control of the code section in which it appears, 39 such as a concurrently 40 executing thread. 41 In the Arduino, the only place that this is likely to occur 42 is in sections 43 of code associated with interrupts, called an interrupt service 44 routine (ISR) */ 45 46 47 48 49void setup() { 50 pinMode(RedPedLED, OUTPUT); 51 // Sets all LED's as OUTPUT 52 pinMode(WhitePedLED, OUTPUT); 53 pinMode(Red1LED, 54 OUTPUT); 55 pinMode(Yellow1LED, OUTPUT); 56 pinMode(Green1LED, OUTPUT); 57 58 pinMode(Red2LED, OUTPUT); 59 pinMode(Yellow2LED, OUTPUT); 60 pinMode(Green2LED, 61 OUTPUT); 62 pinMode(WalkButton, INPUT); // Sets Push Button as INPUT 63 64 65 attachInterrupt(0, pin_ISR, CHANGE); // "Watches" in the background for a 66 button press 67 /* Attach an interrupt to the ISR vector to monitor Push Button. 68 69 Number 0 (for digital pin 2) or number 1 (for digital pin 3) are used. 70 Interrupts 71 are useful for making things happen automatically in 72 microcontroller programs,and 73 can help solve timing problems. 74 Good tasks for using an interrupt may include 75 reading 76 a rotary encoder, or monitoring user input */ 77 78 // Set Initial 79 state of all red LED to HIGH 80 digitalWrite (Red1LED, HIGH); 81 digitalWrite 82 (Red2LED, HIGH); 83 digitalWrite (RedPedLED, HIGH); 84} 85 86 87 88 89void 90 loop() { 91 // put your main code here, to run repeatedly: 92 93 // Station 94 1 Timing 95 delay(2500); // 2.5 Seconds of Red 96 digitalWrite(Red1LED, LOW); 97 // Sets Red1 OFF Green ON 98 digitalWrite(Green1LED, HIGH); 99 delay(15000); 100 // 15 Seconds of Green 101 digitalWrite(Green1LED, LOW); // Sets Green1 OFF 102 Yellow ON 103 digitalWrite(Yellow1LED, HIGH); 104 delay(3500); // 3.5 Seconds 105 of Yellow 106 digitalWrite(Yellow1LED, LOW); // Sets Yellow1 OFF Red ON 107 digitalWrite(Red1LED, 108 HIGH); 109 110 if (WalkRequest == 1) { // If the button has been pressed 111 112 WalkCycle(); // Exit main loop and run WalkCycle () function 113 } 114 115 116 117 118 // Station 2 Timing 119 delay(2500); // 2.5 Seconds of Red 120 digitalWrite(Red2LED, 121 LOW); digitalWrite(Green2LED, HIGH); // Sets Red2 OFF Green ON 122 delay(15000); 123 // 15 Seconds of Green 124 digitalWrite(Green2LED, LOW); digitalWrite(Yellow2LED, 125 HIGH); // Sets Green2 OFF Yellow ON 126 delay(3500); // 3.5 Seconds of Yellow 127 128 digitalWrite(Yellow2LED, LOW); digitalWrite(Red2LED, HIGH); // Sets Yellow2 129 OFF Red ON 130 131 if (WalkRequest == 1) { // If the button has been pressed 132 133 WalkCycle(); // Exit main loop and run WalkCycle () function 134 } 135} 136 137 138 139void 140 WalkCycle() { 141 delay(3500); // 3.5 Second delay before "WALK" begins 142 143 digitalWrite (WhitePedLED, HIGH); digitalWrite (RedPedLED, LOW); // Turn on White 144 Pedestrian Light 145 delay (15000); // 15 Second delay to allow crossing street 146 147 digitalWrite (WhitePedLED, LOW); digitalWrite(WalkButton, LOW); // Turn off White 148 Pedestrian Light 149 delay(250); 150 for (int x = 0; x < 5; x++) { // Flash White 151 Ped LED 5X 152 digitalWrite(WhitePedLED, HIGH); 153 delay(250); 154 digitalWrite(WhitePedLED, 155 LOW); 156 delay(250); 157 } 158 digitalWrite(RedPedLED, HIGH); 159 WalkRequest 160 = 0; // Reset Push Button 161 asm volatile (" jmp 0"); // Soft-reset of sketch. 162 Makes sure Station 1 "MAIN" always gets Green after a walk cycle 163} 164 165 166 167 168void 169 pin_ISR() { 170 buttonState = digitalRead(WalkButton); 171 (WalkRequest = 1); 172 // Walk button has been pressed 173 // digitalWrite(WhitePedLED, buttonState); 174 // Test Light for Interrupt use only during testing! 175}
Downloadable files
trafficsystemwithwalk_r6RVpUxvk5.jpg
trafficsystemwithwalk_r6RVpUxvk5.jpg

Comments
Only logged in users can leave comments