Simple Traffic Light for Arduino

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

4 People Made This Project!

Recommendations

  • Backyard Contest

    Backyard Contest
  • Silly Hats Speed Challenge

    Silly Hats Speed Challenge
  • Arduino Contest 2020

    Arduino Contest 2020

2 Discussions

0
tliguori330
tliguori330

2 years ago

Very clear, Thank you

0
Swansong
Swansong

2 years ago

That's a good simple setup :)