loading
This is my first instructables, so it'll be quite simple. I bought an Arduino, and I decided to make it into a traffic light, but I only had Red and Green LEDs, no yellow or blue. So this is what I made: A traffic Light that flashes 3 times before changing color. 
Before you start, you should know that I'm only 13, so this will be a fun experiment for people who are learning about engineering using the Arduino. It's extremely helpful. I'll also be explaining some basicis about the Arduino during the steps.
So here's what you'll need:
- An Arduino (I'm using the Arduino UNO, but newer kinds will work as well)
- The Arduino software (here is a link to download it: http://www.arduino.cc/en/Main/Software )
- 2 Resistors (mine are 220 ohms ±5%) (That means the marks on it are Red, Red, Brown, Gold)
- 2 wires or any piece of metal to connect the LEDs to the Arduino
- 1 Red LED
- 1 Green LED
- 1 Breadboard (Or the arduino prototype shield, with which you won't even need the wires)
You can get all of this in the "Getting Started with Arduino Kit", which you can get at http://www.makershed.com  for $75.00

Step 1: Board Setup

1. OK, so the first step to your Traffic Light is to set up the Arduino Board
To get started, put the LEDs in the breadboard. If you're using the breadboard that comes with the Kit, you can see that it'll have 10 colums (A-J) with 30 numbered rows. The rows are connected on the same number from A to E and from F to G on any 2 different numbered rows. So you have to put the LEDs in separate numbered rows. I put them in these positions:
Long Green: E15
Short Green: E16
Long Red: E8
Short Red: E9
Now you gotta connect the long legs to the DIGITAL pins and the short legs to ground, using a resistor. There are 2 very convenient GND (ground) pins on the section labeled POWER on the Arduino. I put resistors from A16 to one of them and A9 to the other. Then, using a piece of wire, I connected B8 to DIGITAL pin 9 and B15 to DIGITAL pin 10. There! You're done! Simple as that.

Step 2: Sketch Setup

2. Now that we've connected everything on the board, it's time to make our Arduino Sketch
There are 3 steps to make a sketch, the first is to define your pin names. Pin 9 is the red light and pin 10 is the green light. All you have to do is write the following:

#define R 9
#define G 10

You could call it whatever you want, like Red and Green:

#define Red 9
#define Green 10

Now that you've defined your pins, let's move on to void setup. This tells the Arduino what your pins are for. Usually it'll tell if your pin is an input pin (senses the environment) or an output pin (reacts to the environment). Since LEDs aren't sensors, they're both going to be OUTPUT pins:

void setup ()
{
 pinMode (R, OUTPUT);
 pinMode (G, OUTPUT);
}

IMPORTANT: DO NOT forget the semicolon at the end of each action!!!
Now the hard part begins. You have to turn the green light on, make it blink 3 times, turn it off, and then do the same with the red light. Now you need the void loop. I won't write it down, because it's pretty long, but basically:
digitalWrite (?, HIGH) turns the LED on
digitalWrite (?, LOW) turns it off
delay (????) makes the LED stay the way it is for the number of milliseconds you write down (1000 milliseconds is 1 second)
That's all you need to know. Here is the void loop:

void loop ()
{
  digitalWrite (G, HIGH);
  delay (5000);
  digitalWrite (G, LOW);
  delay (300);
  digitalWrite (G, HIGH);
  delay (1000);
  digitalWrite (G, LOW);
  delay (300);
  digitalWrite (G, HIGH);
  delay (1000);
  digitalWrite (G, LOW);
  delay (300);
  digitalWrite (G, HIGH);
  delay (1000);
  digitalWrite (G, LOW);
  digitalWrite (R, HIGH);
  delay (5000);
  digitalWrite (R, LOW);
  delay (300);
  digitalWrite (R, HIGH);
  delay (1000);
  digitalWrite (R, LOW);
  delay (300);
  digitalWrite (R, HIGH);
  delay (1000);
  digitalWrite (R, LOW);
  delay (300);
  digitalWrite (R, HIGH);
  delay (1000);
  digitalWrite (R, LOW);
} I know it's huge. But just copy and paste it and it should work fine. And there you have it! Just connect the Arduino to your computer, upload the sketch to the Arduino, and there you go! Your very own traffic light!
Sorry I didn't have any good pictures. My camera is horrible. :( 
I hope the video helped!
<p>THANK YOU SOO MUCH!! got my arduino today! i managed to get the program, copy and paste properly the stuff and conect it!! it worked like a charm!! but i said screw the resistors, i didnt put them, i dunno how. but then i managed to put a 220ohm and it reduced slighly the brightness. nr1 nood lesson done. thank you :)</p>
I modified your LED code to add a yellow light.
I like this one...Good at explaning what is going to happen...
I'm working on this now using some relays and a 12 volt light I got here: <a href="http://lanecontrols.com/traffic-lights">http://lanecontrols.com/traffic-lights</a>. Hopefully to plug into an ethernet-shield&nbsp;for internet access.

About This Instructable

7,413views

18favorites

License:

More by Dan_the_Man:Arduino Traffic Light for Beginners 
Add instructable to: