Feb 162011
 

This LED traffic light is a straightforward activity you can try with your arduino. It’s based on a slight variation of the dual LED emergency flasher. To build it you’ll need:

  • 3 LEDs (red, yellow, green)
  • 3 Resistors (470 ohm)
  • breadboard
  • jumper wires
  • arduino

How to connect and program the Arduino:

1) Plug your Arduino into the computer using a USB cable. The power light should come on.

2) Place 3 LEDs in the breadboard such that each has a resistor going from the cathode side to a ground rail on the breadboard.

3) A jumper wire goes from the ground rail to the Gnd pin on the digital side of the Arduino. Then connect the other leg (anode ) of each LED to pins 13,12 and 11 using more jumper wires.

4) Open the Arduino IDE and use the following code. It’s almost identical to the dual Led blink (emergency flasher) code except that an extra pin (#11) has been added to the setup and loop sections and is controlling our red LED.

  void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop(){
  digitalWrite(13, HIGH);
  delay(800);
  digitalWrite(13, LOW);
  delay(50);
  digitalWrite(12,HIGH);
  delay(800);
  digitalWrite(12,LOW);
  delay(50);
  digitalWrite(11,HIGH);
  delay(800);
  digitalWrite(11,LOW);
  delay(50);
}

5) Upload the code to the arduino and it should run automatically!

Challenge:

  • Try adjusting the delay times so that it behaves more like a real traffic light!
 Posted by at 12:03 am

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>