Rahul Bhatia
Published © GPL3+

Model Traffic Light

This project demonstrates how a traffic light works.

BeginnerShowcase (no instructions)881
Model Traffic Light

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
3 mm LED: Red
3 mm LED: Red
×1
3 mm LED: Yellow
3 mm LED: Yellow
×1
3 mm LED: Green
3 mm LED: Green
×1

Software apps and online services

Arduino IDE
Arduino IDE

Code

traffic light code

Arduino
int red = 13;
int yellow = 12;
int green = 11;

void setup(){
pinMode(red,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(green,OUTPUT);
}

void loop(){
changeLights();
delay(15000);
}

void changeLights(){
// green off, yellow for 3 seconds
digitalWrite(green,HIGH);
digitalWrite(yellow,LOW);
delay(3000);

// turn off yellow, then turn red on for 5 seconds
digitalWrite(yellow,LOW);
digitalWrite(red,HIGH);
delay(5000);

// red and yellow on for 2 seconds (red is already on though)
digitalWrite(yellow,HIGH);
delay(2000);

// turn off red and yellow, then turn on green
digitalWrite(yellow,LOW);
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
}

Credits

Rahul Bhatia
8 projects • 0 followers
Btech student 3rd year

Comments