Traffic Lights

To build this example you are going to need the following items:

Hardware

  • Arduino Uno
  • Traffic Light module
  • USB A cable (the sort you use on a printer)

Software

  • Arduino IDE (which can be dowloaded for free from www.arduino.cc)

Instead of the traffic light module you you can use three LEDs but you must use resistors in series with them as well the need for a breadboard. I will show you the circuit diagram for this below.

Wiring Diagram

The wiring diagram for the three LEDs is shown opposite. The breadboard is half size, the resistors are 220Ω (Ohms) [any resistor between 200 and 300 will do]

Components

  • 1 x Arduino Uno
  • 1 x USB-A cable
  • 3 x LEDs
  • 3 x 220Ω (ohm) resistors
  • 7 x male/male jumper leads
  • 1 x 400 point breadboard

Code

  1. int ledRed = 13;
  2. int ledAmber = 12;
  3. int ledGreen = 11;
  4. void setup()
  5. {
  6.   pinMode(ledRed, OUTPUT);
  7.   pinMode(ledAmber, OUTPUT);
  8.   pinMode(ledGreen, OUTPUT);
  9.   digitalWrite(ledAmber, LOW);
  10.   digitalWrite(ledGreen, LOW);
  11.   digitalWrite(ledRed, LOW);
    }
  12. void loop()
  13. {
  14.   digitalWrite(ledRed, HIGH);
  15.   digitalWrite(ledAmber, LOW);
  16.   digitalWrite(ledGreen, LOW);
  17.   delay(3000);
  18.  
  19.   digitalWrite(ledRed, HIGH);
  20.   digitalWrite(ledAmber, HIGH);
  21.   digitalWrite(ledGreen, LOW);
  22.   delay(3000);
  23.  
  24.   digitalWrite(ledGreen, HIGH);
  25.   digitalWrite(ledRed, LOW);
  26.   digitalWrite(ledAmber, LOW);
  27.   delay(3000);
  28.  
  29.   digitalWrite(ledAmber, HIGH);
  30.   digitalWrite(ledGreen, LOW);
  31.   digitalWrite(ledRed, LOW);
  32.   delay(3000);
  33. }