Traffic Lights using Ardino

This project is using Arduino to blink red, yellow and green LEDs. The timing is control by the delay function in the code below. ‘delay(1000)’ = 1 second. Hence below code is delay for 0.5 second, as you can see from the video.

The serial monitor has a baud rate of 9600bits/sec.

int red = 3;
int yellow = 6;
int green = 9;
int counter = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green, OUTPUT);

  digitalWrite(red, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(green, LOW);

  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  counter = counter +1;

  digitalWrite(red, HIGH);
  digitalWrite(yellow, LOW);
  digitalWrite(green, LOW);
  Serial.println("Light Mode : Red");
  delay(500);
 
  
  digitalWrite(red, LOW);
  digitalWrite(yellow, HIGH);
  digitalWrite(green, LOW);
  Serial.println("Light Mode : Yellow");
  delay(500);
  
  digitalWrite(red, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(green, HIGH);
  Serial.println("Light Mode : Green");
  delay(500);

  Serial.print("Count = ");
  Serial.println(counter);
  

}

Below are the videos for the project. The 2nd video is the serial monitor output.

Traffic Light
Serial Monitor Output