loading
Have you ever made a city out of Legos? I know i have built many of them but they all missed something... Traffic lights!
So i decided to make my very own traffic light setup from my arduino board.

Step 1: You Will Need:

You will need:

An arduino board
Red, Green and amber LED's
Three 220 Ohm Resistors

Optional:

Wire
and an Protoshield

Step 2: Get the Components

I assume you already have an adruino board, and maybe also a Protoshield.

You'll need the LED's and resistors

the 220 Ohm resistors are color coded so: Red, Red, Brown

Step 3: Hook Up to the Board

Since this is a really simple project we only need 3 digital pins and ground.

Put the LED's in the breadboard/protoboard and use the resistors to connect them to the digital pins,

Green to pin 8
Yellow to pin 9
and Red to pin 10

then connect all the negative pins of the LED's together and to ground.

Step 4: Upload the Code!

Again, since this is a really simple project the code is also simple,
just copy it from below and upload it to your board via USB.

int greenled = 8; //Led's and pins
int yellowled = 9;
int redled = 10;

void setup()
{
pinMode(greenled, OUTPUT); //Pinmodes of the leds
pinMode(yellowled, OUTPUT);
pinMode(redled, OUTPUT);
}

void loop()
{
digitalWrite(greenled, HIGH); //Green on for 5 seconds
delay(5000);
digitalWrite(greenled, LOW); //Green off, yellow on for 2 seconds
digitalWrite(yellowled, HIGH);
delay(2000);
digitalWrite(yellowled, LOW); //yellow off, red on for 5 seconds
digitalWrite(redled, HIGH);
delay(5000);
digitalWrite(yellowled, HIGH); //Yellow and red on for 2 seconds
delay(2000);
digitalWrite(redled, LOW); //Red and Yellow off
digitalWrite(yellowled, LOW);
}

Step 5: Watch Your Traffic Being Controlled :)

Now you can see your very own traffic lights, control traffic.
the lights change according to European standards.

<p>i would like to make traffic light using red and green light only.</p><p>so, shoud i just delete the amber color ?? need help here. thank you</p>
<p>Nice build, wrote nearly the same too ;-). Only modification: Make the delay variable for impatient kids or realistic crowded cities.</p><p>void loop() {</p><p> // WAIT</p><p> digitalWrite(RED, HIGH);</p><p> digitalWrite(YELLOW, LOW );</p><p> digitalWrite(GREEN, LOW );</p><p> delay(DELAY*3);</p><p> // START</p><p> digitalWrite(RED, HIGH);</p><p> digitalWrite(YELLOW, HIGH );</p><p> digitalWrite(GREEN, LOW );</p><p> delay(DELAY);</p><p> // GO</p><p> digitalWrite(RED, LOW );</p><p> digitalWrite(YELLOW, LOW );</p><p> digitalWrite(GREEN, HIGH);</p><p> delay(DELAY*2);</p><p> // STOP</p><p> digitalWrite(RED, LOW );</p><p> digitalWrite(YELLOW, HIGH );</p><p> digitalWrite(GREEN, LOW);</p><p> delay(DELAY);</p><p>}</p>
thanks for this - I did this with an impatient almost 3yr old watching. Didn't even have to think about the code, just burn myself with a soldering iron.
<p>Had fun building the double traffic lights. I changed the code to work like actual traffic lights. Here is the change.<br><br>int g1 = 8;<br>int y1 = 9;<br>int r1 = 10;<br>int r2 = 13;<br>int y2 = 12;<br>int g2 = 11;<br>void setup()<br>{<br>pinMode(g1, OUTPUT);<br>pinMode(y1, OUTPUT);<br>pinMode(r1, OUTPUT);<br>pinMode(r2, OUTPUT);<br>pinMode(y2, OUTPUT);<br>pinMode(g2, OUTPUT);<br>}<br>void loop()<br>{<br>digitalWrite(r1, HIGH);<br>digitalWrite(g2, HIGH);<br>delay(8000);<br>digitalWrite(g2, LOW);<br>digitalWrite(y2, HIGH);<br>delay(6000);<br>digitalWrite(y2, LOW);<br>digitalWrite(r2, HIGH);<br>delay(50);<br>digitalWrite(r1,LOW);<br>digitalWrite(g1, HIGH);<br>delay(8000);<br>digitalWrite(g1, LOW);<br>digitalWrite(y1, HIGH);<br>delay(6000);<br>digitalWrite(y1, LOW);<br>digitalWrite(r1, HIGH);<br>delay(50);<br>digitalWrite(r2,LOW);<br>}</p>
<p>its a lot of fun this project if made it i also made a double traffic light here is the code for it </p><p>#define DELAYg 2000</p><p>#define DELAYy 1000</p><p>#define DELAYr 2500</p><p>int g1 = 8;</p><p>int y1 = 9;</p><p>int r1 = 10;</p><p>int r2 = 13;</p><p>int y2 = 12;</p><p>int g2 = 11;</p><p>void setup()</p><p>{</p><p>pinMode(g1, OUTPUT); </p><p>pinMode(y1, OUTPUT);</p><p>pinMode(r1, OUTPUT);</p><p>pinMode(r2, OUTPUT);</p><p>pinMode(y2, OUTPUT);</p><p>pinMode(g2, OUTPUT);</p><p>}</p><p>void loop()</p><p>{</p><p>digitalWrite(r1, HIGH);</p><p>digitalWrite(g2, HIGH);</p><p>delay(DELAYg);</p><p>digitalWrite(g2, LOW); </p><p>digitalWrite(y2, HIGH);</p><p>delay(DELAYy);</p><p>digitalWrite(y2, LOW);</p><p>digitalWrite(r2, HIGH);</p><p>delay(DELAYr);</p><p>digitalWrite(r1,LOW);</p><p>digitalWrite(g1, HIGH);</p><p>delay(DELAYg);</p><p>digitalWrite(g1, LOW); </p><p>digitalWrite(y1, HIGH);</p><p>delay(DELAYy);</p><p>digitalWrite(y1, LOW);</p><p>digitalWrite(r1, HIGH);</p><p>delay(DELAYr);</p><p>digitalWrite(r2,LOW);</p><p>}</p>
<p>Thank you for code and inspiration, we made it and have fun.</p>
great... for me, I found an amber LED looks a more natural color for this..
Nice job ...but here is the fix for the red,yellow, green. It is incorrect The traffic lights goes as follows green, yellow,red... then red,green (not red,yellow.green). <br>Enjoy;) <br>CODE: <br> <br>int greenled = 8; //Led's and pins <br>int yellowled = 9; <br>int redled = 10; <br> <br>void setup() <br>{ <br>pinMode(greenled, OUTPUT); //Pinmodes of the leds <br>pinMode(yellowled, OUTPUT); <br>pinMode(redled, OUTPUT); <br>} <br> <br>void loop() <br>{ <br>digitalWrite(greenled, HIGH); //Green on for 5 seconds <br>delay(5000); <br>digitalWrite(greenled, LOW); //Green off, yellow on for 2 seconds <br>digitalWrite(yellowled, HIGH); <br>delay(2000); <br>digitalWrite(yellowled, LOW); //yellow off, red on for 5 seconds <br>digitalWrite(redled, HIGH); <br>delay(5000); <br>digitalWrite(redled, LOW); //Red and Yellow off <br>digitalWrite(yellowled, LOW); <br>}
As I said, this is according to icelandic (european?) standards, not American
Ok My bad
Thanks for this useful materiel
Thanks again for responding. Yes, I am quite familiar with Google, and sorry if this isn't the &quot;right place&quot; to ask. BUT when I went to Google and found the Arduino home page, the Arduino was described as an &quot;open source electronics prototype platform&quot; etc. All I wanted was a simple answer, because I had no clue after reading the home page. So thanks, again. Obviously I am not an electronics hobbyist. Just trying to catch up a little on the technology. By the way, &quot;lingo is an old slang term for &quot;language&quot; and &quot;loop&quot; is another old, outdated slang term for &quot;information loop&quot; or in other words, &quot;lingo loop&quot; would mean &quot;techno speak&quot;, referring to the language of the &quot;informed electronics technical people&quot; like you.
Thanks for your reply to my comment. All I meant was that I am new to some of the terminology and behind in the technology, What is an Arduino?<br>Thanks,<br>B2Bsurvivor
Well, i don't think this is the right place to ask that but i'll give you the short answer. Arduino is a very popular Microcontroller among hobbyists, like me. <br><br>Hope that answers your question ad remember, &quot;Google is your best friend&quot;
Looks like a great project. So please help me out here, I'm out of the lingo loop. What is the Arduino reference all about?
Hmmm, I don't really know what you mean? &quot;Lingo Loop&quot; never heard of that? Help me out here so i can help you ;)
Good instructable! This is great for beginner arduino users! Brotip: only one resistor is required, put it between the LED's ground and arduino ground. this helps save resistors for other projects!

About This Instructable

68,619views

79favorites

License:

More by bjarni1995:Using FM RC Controllers with Arduino Simple Arduino Traffic Lights 
Add instructable to: