In Arduino based traffic light demonstration tutorial, we’ll learn to implement a simple traffic light system using some led’s, resistors, and Arduino. Traffic light Sequence will change after every 4 seconds.
Materials required:
Arduino uno
ULN2803 (NPN darlington pair)
Red, Green, Yellow Led’s
330 ohms
resistors
Source code
int ledPins[] = { 1,2,3,4,5,6,7,8,9,10,11,12}; int pinCount = 12; void setup() { for (int thisPin = 0; thisPin < pinCount; thisPin++) { pinMode(ledPins[thisPin], OUTPUT); } } void loop() { digitalWrite(r1, HIGH); +digitalWrite(r2, HIGH); digitalWrite(r3, HIGH); digitalWrite(r4, HIGH); digitalWrite(y1, HIGH); digitalWrite(y2, HIGH); digitalWrite(y3, HIGH); digitalWrite(y4, HIGH); digitalWrite(g1, HIGH); digitalWrite(g2, HIGH); digitalWrite(g3, HIGH); digitalWrite(g4, HIGH); delay(4000); digitalWrite(r1, HIGH); digitalWrite(r2, HIGH); digitalWrite(r3, HIGH); digitalWrite(r4, LOW); digitalWrite(y1, LOW); digitalWrite(y2, LOW); digitalWrite(y3, LOW); digitalWrite(y4, LOW); digitalWrite(g1, LOW); digitalWrite(g2,LOW); digitalWrite(g3, LOW); digitalWrite(g4, HIGH); delay(4000); digitalWrite(r1, HIGH); digitalWrite(r2, HIGH); digitalWrite(r3, LOW); digitalWrite(r4, LOW); digitalWrite(y1, LOW); digitalWrite(y2, LOW); digitalWrite(y3, HIGH); digitalWrite(y4, HIGH); digitalWrite(g1, LOW); digitalWrite(g2,LOW); digitalWrite(g3, LOW); digitalWrite(g4, LOW); delay(4000); digitalWrite(r1, HIGH); digitalWrite(r2, HIGH); digitalWrite(r3, LOW); digitalWrite(r4, HIGH); digitalWrite(y1, LOW); digitalWrite(y2, LOW); digitalWrite(y3, LOW); digitalWrite(y4, LOW); digitalWrite(g1, LOW); digitalWrite(g2,LOW); digitalWrite(g3, HIGH); digitalWrite(g4, LOW); delay(4000); digitalWrite(r1, HIGH); digitalWrite(r2, LOW); digitalWrite(r3, LOW); digitalWrite(r4, HIGH); digitalWrite(y1, LOW); digitalWrite(y2, HIGH); digitalWrite(y3, HIGH); digitalWrite(y4, LOW); digitalWrite(g1, LOW); digitalWrite(g2,LOW); digitalWrite(g3, LOW); digitalWrite(g4, LOW); delay(4000); digitalWrite(r1, HIGH); digitalWrite(r2, LOW); digitalWrite(r3, HIGH); digitalWrite(r4, HIGH); digitalWrite(y1, LOW); digitalWrite(y2, LOW); digitalWrite(y3, LOW); digitalWrite(y4, LOW); digitalWrite(g1, LOW); digitalWrite(g2,HIGH); digitalWrite(g3, LOW); digitalWrite(g4, LOW); delay(4000); digitalWrite(r1, LOW); digitalWrite(r2, LOW); digitalWrite(r3, HIGH); digitalWrite(r4, HIGH); digitalWrite(y1, HIGH); digitalWrite(y2, HIGH); digitalWrite(y3, LOW); digitalWrite(y4, LOW); digitalWrite(g1, LOW); digitalWrite(g2,LOW); digitalWrite(g3, LOW); digitalWrite(g4, LOW); delay(4000); digitalWrite(r1, LOW); digitalWrite(r2, HIGH); digitalWrite(r3, HIGH); digitalWrite(r4, HIGH); digitalWrite(y1, LOW); digitalWrite(y2, LOW); digitalWrite(y3, LOW); digitalWrite(y4, LOW); digitalWrite(g1, HIGH); digitalWrite(g2,LOW); digitalWrite(g3, LOW); digitalWrite(g4, LOW); delay(4000); digitalWrite(r1, LOW); digitalWrite(r2, HIGH); digitalWrite(r3, HIGH); digitalWrite(r4, LOW); digitalWrite(y1, HIGH); digitalWrite(y2, LOW); digitalWrite(y3, LOW); digitalWrite(y4, HIGH); digitalWrite(g1, LOW); digitalWrite(g2,LOW); digitalWrite(g3, LOW); digitalWrite(g4, LOW); delay(4000); }
0 Comments