Two-way Traffic Control System Using Arduino

Two-way Traffic Control System Using Arduino

Jul 17, 2023 - 21:36
 20
Two-way Traffic Control System Using Arduino
Two-way Traffic Control System Using Arduino
The components that are required are: 
 
1.  6 LEDs (2 Red, 2 Yellow,2 Green)
2. Breadboard.
3. Arduino Uno
4. Jumper Wires
5.6 x 220ohm Resistors
The circuit diagram:
 
 
The Code:
// C++ code
//
int green=13;
 int yellow=12;
 int red=11;
 int green2=10;
 int yellow2=9;
 int red2=8;
 void setup() {
  pinMode(green, OUTPUT);
  pinMode(yellow , OUTPUT);
  pinMode(red , OUTPUT);
  pinMode(green2, OUTPUT);
  pinMode(yellow2 , OUTPUT);
  pinMode(red2 , OUTPUT);
  digitalWrite(green ,HIGH);
  digitalWrite(yellow ,HIGH);
  digitalWrite(red ,HIGH);
  digitalWrite(green2 ,HIGH);
  digitalWrite(yellow2 ,HIGH);
  digitalWrite(red2 ,HIGH);
  delay(1000);
  digitalWrite(green ,LOW);
  digitalWrite(yellow ,LOW);
  digitalWrite(red ,LOW);
  digitalWrite(green2 ,LOW);
  digitalWrite(yellow2 ,LOW);
  digitalWrite(red2 ,LOW);
 }
 /* dual line traffic light
  * http://www.techhubmega.blogspot.com
  * WRITER IS AMIR PHILIP
  * route 1 red led time = route 1 red led time [1] + route 1 red led time [2]
  * route 2 red led time = route 2 red led time [2] + route 2 red led time [2]
  * route 1 total red led time = 1 second or 60000 ms
  * route 2 total red led time = 1 second or 60000 ms
  */
 void loop() {
  digitalWrite(green ,HIGH);
  digitalWrite(red2 ,HIGH);
  delay(1000); /* route 1 green led time and route 2 red led time [1] */
  digitalWrite(green ,LOW);
  digitalWrite(yellow ,HIGH);
  delay(1050); /* route 1 yellow led time and route 2 red led time [2] */
  digitalWrite(yellow ,LOW);
  digitalWrite(red ,HIGH);
  digitalWrite(red2 ,LOW);
  digitalWrite(green2 ,HIGH);
  delay(1450); /* route 1 red led time [1] and route 2 green led time */
  digitalWrite(green2 ,LOW);
  digitalWrite(yellow2 ,HIGH);
  delay(1050); /* route 1 red led time [2] and route 2 yellow led time */
  digitalWrite(red ,LOW);
  digitalWrite(yellow2 ,LOW);
 }
The resulting output;