Arduino Based 3-Way Traffic Light Controller
Components Required:
- 3*Red LED Lights
- 3*Green LED Lights
- 3*Yellow LED Lights
- 3*220ohm Resistors
- Breadboard
- Male To Male Connectors
- Arduino Uno With Ide Cable
CODE
void setup() {
// configure the output pins
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
void loop()
{
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(8,1);
digitalWrite(2,0);
digitalWrite(6,0);
digitalWrite(3,0);
digitalWrite(7,0);
digitalWrite(10,0);
digitalWrite(9,0);
delay(5000);
digitalWrite(6,1);
digitalWrite(5,0);
delay(1000);
digitalWrite(2,1);
digitalWrite(8,1);
digitalWrite(7,1);
digitalWrite(3,0);
digitalWrite(6,0);
digitalWrite(9,0);
digitalWrite(5,0);
digitalWrite(10,0);
digitalWrite(4,0);
delay(5000);
digitalWrite(9,1);
digitalWrite(8,0);
delay(1000);
digitalWrite(5,1);
digitalWrite(2,1);
digitalWrite(10,1);
digitalWrite(6,0);
digitalWrite(8,0);
digitalWrite(4,0);
digitalWrite(7,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,0);
delay(5000);
digitalWrite(3,1);
digitalWrite(2,0);
delay(1000);
}
{
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(8,1);
digitalWrite(2,0);
digitalWrite(6,0);
digitalWrite(3,0);
digitalWrite(7,0);
digitalWrite(10,0);
digitalWrite(9,0);
delay(5000);
digitalWrite(6,1);
digitalWrite(5,0);
delay(1000);
digitalWrite(2,1);
digitalWrite(8,1);
digitalWrite(7,1);
digitalWrite(3,0);
digitalWrite(6,0);
digitalWrite(9,0);
digitalWrite(5,0);
digitalWrite(10,0);
digitalWrite(4,0);
delay(5000);
digitalWrite(9,1);
digitalWrite(8,0);
delay(1000);
digitalWrite(5,1);
digitalWrite(2,1);
digitalWrite(10,1);
digitalWrite(6,0);
digitalWrite(8,0);
digitalWrite(4,0);
digitalWrite(7,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,0);
delay(5000);
digitalWrite(3,1);
digitalWrite(2,0);
delay(1000);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น