Introduction: Another Arduino Taffic Light
Step 1: The Parts
1 - Arduino (Obvious)
1 - Breadboard
6 - 270 ohm resistors
2 - Red LED
2 - Yellow LED
2 - Green LED
Misc. - Wires and Patients.
Step 2: Wiring
I used Pins 2 - 7 to make things easy. I don't know if it hurts the Arduino to use both PWM and standard pins or not but, It works.
I wired up the grounds to the ground rail through the 270 OHM Resistors, it seems backwards to me, because I'm and electrician, to go to ground through a resistor but, I have seen this alot.
I took the 6 LED's Anode lead and wired......
Side 1 Side 2
1 - Red to Pin 2 2 - Red to 5
1 - Yellow to 3 2 - Yellow to 6
1 - Green to 4 2 - Green to 7
Step 3: The Code
I hope I didn't miss anything but if I did just comment.
The code I use seems simple, But I got confused so I had to get some help on figuring out what did what to who and how many.
There are some commented out sections that could come into play later.
void setup(){
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop(){
digitalWrite(2, HIGH); //Side 1 Red ON
delay(100);
digitalWrite(7, HIGH); //Side 2 Green ON
delay(5000);
digitalWrite(7, LOW); //Side 2 GREEN OFF
// delay(2000);
digitalWrite(6, HIGH); //Side 2 Yellow ON
delay(2000);
digitalWrite(6, LOW); //Side 2 Yellow OFF
// delay(2000);
digitalWrite(5, HIGH); //Side 2 Red ON
delay(100);
digitalWrite(2, LOW); //Side 1 Red OFF
// delay(2000);
digitalWrite(4, HIGH); //Side 1 Green ON
delay(5000);
digitalWrite(4, LOW); //Side 1 Green OFF
// delay(1000);
digitalWrite(3, HIGH); //Side 1 Yellow ON
delay(2000);
digitalWrite(3, LOW); //Side 1 Yellow OFF
// delay(1000);
digitalWrite(5, LOW); //Side 2 Red OFF
// digitalWrite(2,LOW); //Side 1 Red
// delay(1000);
}
7 Comments
3 years ago
Thank You so much
9 years ago on Introduction
I'm going to work on another that has the pedestrian switch, one side will stop traffic and the other side will let traffic go. Sounds neat anyway.
9 years ago on Introduction
On the video you said this is your first time using C++, but I didn't think it was possible to program the arduino using that language.
Reply 9 years ago on Introduction
I said that because I thought it was c++. I'm used to vb. Could you help me in correcting my statement? What language is it?
Reply 9 years ago on Introduction
Good instructable by the way.
Reply 9 years ago on Introduction
Thank you HIggs. It is my first Instructable.
Reply 9 years ago on Introduction
Not really sure. I know it is some variation of c++, but obviously not exactly the same thing. it is simplified and some commands are changed. Over all though it is very similar to c/c++.