Simple Traffic Light for Arduino

Published

Introduction: 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

    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Oil Contest

      Oil Contest

    2 Discussions

    Very clear, Thank you

    That's a good simple setup :)