stannano
Published © Apache-2.0

Traffic Lights!!

Make simple traffic lights, and then learn how to add a button!

BeginnerFull instructions provided404
Traffic Lights!!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
Use any board but remember to change the pins!
×1
LED (generic)
LED (generic)
×3
Resistor 10k ohm
Resistor 10k ohm
×3

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 170 Pin
Breadboard, 170 Pin
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long

Story

Read more

Schematics

The schematic

Code

Untitled file

Arduino
int red = 10;
int yellow = 9;
int green = 8;
void setup(){
    pinMode(red, OUTPUT);
    pinMode(yellow, OUTPUT);
    pinMode(green, OUTPUT);
}
void loop(){
    changeLights();
    delay(15000);
}
void changeLights(){
    // green off, yellow on for 3 seconds
    digitalWrite(green, LOW);
    digitalWrite(yellow, HIGH);
    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);
    delay(3000);
}

Credits

stannano
5 projects • 3 followers

Comments