Introduction: Simple Traffic Light for Arduino

Picture of 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:

Picture of

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.

Comments

tliguori330 (author)2017-11-21

Very clear, Thank you

Swansong (author)2017-11-21

That's a good simple setup :)

About This Instructable

80views

2favorites

License:

More by ramirudensky:Simple Traffic Light for Arduino
Add instructable to: