Here is How to Create LED DIY Arduino Traffic Light – Pedestrian Light Push Button Control. When Pedestrians Will WALK, Cars Will Stop Logic.There is actually two parts – one is building the LED DIY Traffic Lights and Second Part is the Coding. We are using push button, but it can be a sensor in real. Most commonly many websites write about Arduino Traffic Light which automatically goes OFF and ON. That is not practical, it is more towards toy. It is example of basic implementation of Finite State Machines modeling in embedded.
Creating DIY Arduino Traffic Light Pedestrian Light
This should be a separate chapter. Raspberry has great pre-built traffic light add-ons like PI-TRAFFIC, PI-STOP, Traffic HAT and so on. But they cost minimum $10 for a set of two. Additionally we are not getting the desired realistic Pedestrian Light. For total 5 LEDs, it is meaningless to pay $10. We are taking about this stuff :
You can mount the LED on PCB to get such thing or just put them over simple corrugated board or 3D Print or use LEGO blocks. WALK/GO LED can be created by adding those shaped cover.
---
DIY Arduino Traffic Light Pedestrian Light : Logic
When push button is pressed :
- the green LED of Traffic Light will turn off
- and yellow LED of Traffic Light will turn on for 2 seconds
- then the red LED of Traffic Light will go to ON
- by that time the green LED of Pedestrian Light will turn on
- After 4 seconds the green LED of Pedestrian Light will be flashing for 5 seconds and turn off
- Red LED of Pedestrian Light will be on, red LED of Traffic Light will off, green LED of Traffic Light will be on.
Creating DIY Arduino Traffic Light Pedestrian Light : Circuit Diagram and Code
We have the whole project on FritZing and you can download from this link. Download the .fzz
and .ino
file from there. Here is also the code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | int TrafficRed = 3; int TrafficYellow = 4; int TrafficGreen = 5; int PedestrianRed = 8; int PedestrianGreen = 9; int button = 13; int crossTime = 4000; unsigned long buttonGap ; void setup () { pinMode(TrafficRed, OUTPUT); pinMode(TrafficYellow, OUTPUT); pinMode(TrafficGreen, OUTPUT); pinMode(PedestrianRed, OUTPUT); pinMode(PedestrianGreen, OUTPUT); pinMode(button, INPUT); digitalWrite(TrafficGreen,HIGH); digitalWrite(PedestrianRed, HIGH); } void loop(){ int state = digitalRead(button); if(state==HIGH && (millis() - buttonGap) > 5000) { switchLights(); } } void switchLights() { digitalWrite(TrafficGreen,LOW); digitalWrite(TrafficYellow,HIGH); delay(2000); digitalWrite(TrafficYellow,LOW); digitalWrite(TrafficRed,HIGH); delay(1000); digitalWrite(PedestrianRed,LOW); digitalWrite(PedestrianGreen,HIGH); delay(crossTime); for (int x=0; x<10; x++){ digitalWrite(PedestrianGreen,HIGH); delay(250); digitalWrite(PedestrianGreen,LOW); delay(250); } digitalWrite(PedestrianRed, HIGH); delay(100); digitalWrite(TrafficRoadGreen,HIGH); digitalWrite(TrafficRoadRed,LOW); buttonGap = millis(); } |
The code is modified from http://osoyoo.com/?p=239
and is distributed under GNU GPL 3.0 License.