Simple Traffic Light for Arduino

Intro: Simple Traffic Light for Arduino

This Instructable will show you how to construct a Traffic Light for Arduino, cycling through LEDs for green, yellow, and res lights.

Step 1:

The Materials:

3 LEDs (red, yellow, and green lights)
Connecting wires
Arduino board
Breadboard
Resistors (220)

Step 2:

The Setup:
The long leg of each LED should be connected (using a 220 resistor) to the digital pins 8,9,10.
Each short leg goes to ground.
The wire connections should look like this diagram. C

Step 3:

Finally, once the setup has been completed, all that is left is the code, which looks like this:

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 (){
digitalWrite (green, LOW);
digitalWrite (yellow, HIGH);
delay (3000);
digitalWrite (yellow, LOW);
digitalWrite (red, HIGH);
delay (5000);
digitalWrite (yellow, HIGH);
delay (2000);
digitalWrite (yellow, LOW);
digitalWrite (red, LOW);
digitalWrite (green, HIGH);
delay (3000);
}

Step 4:

Once the code has been uploaded to the Arduino, your Traffic Light should be in working order, cycling through the three colors.

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Audio Contest 2018

      Audio Contest 2018

    2 Discussions

    0
    None
    tliguori330

    10 months ago

    Very clear, Thank you

    0
    None
    Swansong

    10 months ago

    That's a good simple setup :)