Secondary Menu

Traffic Light Model

Introduction: Traffic Light Model

We are all familiar with traffic lights -- they are one of our biggest pet peeves, yet creates order in society by giving us all a common understanding needed for navigating cars. Traffic lights are one of the great advances in technologies, many take for granted. Prior to the invention of timed traffic lights, multiple people would have to manually direct the traffic, with a popular example is the London Bridge.

This project introduces the fundamental skill of driving multiple LEDs, understanding timing, and programming digital output signals using an Arduino; learning by design.

Step 1: Tools and Materials

Arduino Uno

Breadboard

Green LEDYellow LEDRed LED

Jumper Wires

100 Ohm Resistors

Step 2: Connecting the LEDs to Arduino

Connect the ground pin, indicated as flat edges of the LED, to ground. Since the Arduino only has limited ground pins, connect them to a common ground indicated as the blue bar on the breadboard

Connect any pin in this bleu bar on the breadboard to any ground pin on the Arduino. Now all the LEDs are hooked up to ground

Connect the positive terminal of each of the LEDs to a 100Ω Resistor.

Then, connect the Red LED's resistor to the digital pin 11 of the Arduino. This is indicated as the Orange Wire.

Similarly, connect the Yellow LED's resistor to the digital pin 10 of the Arduino. This is indicated as the Yellow Wire.

Finally, connect the Green LED's resistor to the digital pin 9 of the Arduino. This is indicated as the White Wire.

Make sure them like traffic lights, where red is on top, followed by yellow, and then green.

// write a custom function that sets a particular coloured LED ON or off
void setLights(int red, int yellow, int green) {
// sets each of the coloured lights according to the parameters passed by the user
// control a colour as they wish by using 1 as high and 0 as low
digitalWrite(redPin, red);
digitalWrite(yellowPin, yellow);
digitalWrite(greenPin, green);
}

Step 4: Traffic Model Demo

The code is a demonstration of a sped up traffic light, and does not reflect the actual timing of the traffic light, since it would be quite a long and boring video demonstration. Here, it is demonstrated that the light will cycle through green, yellow, then red.

Changing the delays allows for the line of code preceding the delay to continue running until the delay count is finished.

Metalworking Contest

Fix It! Contest

Creative Misuse Contest

2 Discussions

This brings back some memories. Back decades ago we had to code (in machine language) a 6502 8-bit microprocessor for a typical four way traffic light. Not as easy as it looks. But it was a great computer class all the same. Nice project!