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 LED
    Yellow LED
    Red LED
  • Jumper Wires
  • 100 Ohm Resistors

Step 2: Connecting the LEDs to Arduino

  1. 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
  2. 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
  3. Connect the positive terminal of each of the LEDs to a 100Ω Resistor.
  4. Then, connect the Red LED's resistor to the digital pin 11 of the Arduino. This is indicated as the Orange Wire.
  5. Similarly, connect the Yellow LED's resistor to the digital pin 10 of the Arduino. This is indicated as the Yellow Wire.
  6. 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.

Step 3: Coding

// declare the pin wherein the red, yellow and green LEDs are connected, respectively
int redPin = 9;
int yellowPin = 10; 
int greenPin = 11;
void setup() { 

// declare each of the coloured pins as digital output signals
pinMode(redPin, OUTPUT); 
pinMode(yellowPin, OUTPUT); 
pinMode(greenPin, OUTPUT); 

void loop() {

// green light
setLights (0, 0, 1); // stay at a green light for 5 seconds delay(5000);
// yellow light setLights (0, 1, 0); // stay at a yellow light for 1 second or 1000 milliseconds delay(1000);
// stop light 
setLights (1, 0, 0); // stay at a stop light for 5 seconds or 5000 milliseconds delay(5000);
// 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.

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017