US Traffic Lights

I had seen traffic light projects all over the internet for a long time. They are great programs, but they all seem to simulate the European traffic lights. :frowning:
Well, I thought about it a litte, :-/ , and decided to make a set of US traffic lights for a change. :smiley:
It took a couple hours, but Here It Is..... without pedestrian cross buttons of course.

This is set up to simulate both the North/South lights and the East/West lights. Just connect 2 of each light to an output and place them on opposite sides of the pole.

I will try and put together an actual traffic light sometime and show you the whole thing in action. Haven't ever created an internet video before, so I need to figure everything out. :stuck_out_tongue:

Hope everyone likes it. :wink:

Dan

Fritz BB:

Code:

/* real_us_traffic_lights2.pde
   By: Daniel Wright
   2010.JAN.30
   I kept seeing all these Traffic Light programs on the internet
   and I was real unhappy that they were all European style.
   No one had made a US Traffic light. Well, Here it is! 
   Realistic US Traffic Lights without cross walk buttons.
   I am going to work on a model with the Pedestrian cross walk
   buttons next.
*/
int carRed1 = 12; // assign the car1 lights
int carYellow1 = 11;
int carGreen1 = 10;
int carRed2 = 9; // assign the car2 lights
int carYellow2 = 8;
int carGreen2 = 7;
int pedRed1 = 6; // assign the pedestrian1 lights
int pedGreen1 = 5;
int pedRed2 = 4; // assign the pedestrian2 lights
int pedGreen2 = 3;
int crossTime = 10000; // time allowed to cross

void setup() {
pinMode(carRed1, OUTPUT);
pinMode(carYellow1, OUTPUT);
pinMode(carGreen1, OUTPUT);
pinMode(pedRed1, OUTPUT);
pinMode(pedGreen1, OUTPUT);
pinMode(carRed2, OUTPUT);
pinMode(carYellow2, OUTPUT);
pinMode(carGreen2, OUTPUT);
pinMode(pedRed2, OUTPUT);
pinMode(pedGreen2, OUTPUT);

// initialize the lights
digitalWrite(carGreen1, HIGH);
digitalWrite(carRed2, HIGH);
digitalWrite(pedGreen1, HIGH);
digitalWrite(pedRed2, HIGH);
}

void loop() {
delay(crossTime); // wait for preset time period

digitalWrite(pedGreen1, LOW); //Turn ped green 1 off

// flash the ped red 1
for (int x=0; x<10; x++) {
digitalWrite(pedRed1, HIGH);
delay(250);
digitalWrite(pedRed1, LOW);
delay(250);
}
digitalWrite(carGreen1, LOW); // car green 1 off
digitalWrite(carYellow1, HIGH); // car yellow 1 on

// flash the ped red 1
for (int x=0; x<10; x++) {
digitalWrite(pedRed1, HIGH);
delay(250);
digitalWrite(pedRed1, LOW);
delay(250);
}
digitalWrite(pedRed1, HIGH); // ped red 1 on

delay(2000); // wait 2 seconds

digitalWrite(carYellow1, LOW); // car yellow 1 off
digitalWrite(carRed1, HIGH); // car red 1 on

delay(1000); // wait 1 second till its safe

digitalWrite(pedRed2, LOW); // ped red 2 off
digitalWrite(carRed2, LOW); // car red 2 off
digitalWrite(pedGreen2, HIGH); // ped green 2 on
digitalWrite(carGreen2, HIGH); // car green 2 on

delay(crossTime); // wait for preset time period

digitalWrite(pedGreen2, LOW);

// flash the ped red 2
for (int x=0; x<10; x++) {
digitalWrite(pedRed2, HIGH);
delay(250);
digitalWrite(pedRed2, LOW);
delay(250);
}

digitalWrite(carGreen2, LOW); // car green 2 off
digitalWrite(carYellow2, HIGH); // car yellow 2 on

// flash the ped red 2
for (int x=0; x<10; x++) {
digitalWrite(pedRed2, HIGH);
delay(250);
digitalWrite(pedRed2, LOW);
delay(250);
}

digitalWrite(pedRed2, HIGH); // ped red 2 on

delay(2000); // wait 2 seconds

digitalWrite(carYellow2, LOW); // car yellow 2 off
digitalWrite(carRed2, HIGH); // car red 2 on

delay(1000); // wait 1 second till its safe

digitalWrite(pedGreen2, LOW); //ped green 2 off
digitalWrite(pedRed1, LOW); //ped red 1 off
digitalWrite(carRed1, LOW); //car red 1 off
digitalWrite(pedGreen1, HIGH); // ped green 1 on
digitalWrite(carGreen1, HIGH); //car green 1 on
}

Can you just explain the differences between the US/Euro traffics lights (as I live in niether of these palces :))

Sure mattd.

The European lights go from green to yellow to red on one street then from red to yellow to green on the other street. When time is up it reverses the sequence.

The US lights go from green to yellow to red on one street then from red to green on the other street. Then the street that is currently green goes to yellow then red then the first street goes from red to green.

The US lights only use the yellow when they are in the process of changing red.

Hope this helps.... :-/

Dan

And its worth adding that in some US states, red means stop, green means go, and yellow means go faster :wink:

The European lights go from green to yellow to red on one street then from red to yellow to green on the other street. When time is up it reverses the sequence

I'm in Europe, and here the lights go from green to amber, to red, and then on the other street from red to red AND amber and then to green.

there are a lot of different systems ins europ!

austria and germany are the same, but italy is different to that, and the uk is different to both.

one europ, but 10.000 trafficlightsystems :-?

I've noticed in some towns (not all) here is California that when one direction turns to red there is a few seconds delay until the opposite direction turns green. Probably to allow a little time for the red light blowers to clear the intersection. :wink:

Lefty

My little program actually has a little delay like that too.
Unintentional, but it's there... :smiley:

Hi, I'm italian.
Here the sequence is:
Green => Green+yellow => Red
and
Red => Green

but here sometimes the sequence is:
Green => OFF (forever) :smiley:

What I wish they would do is add a countdown timer to the yellow, so you know if you can make it or not; make the number black on yellow, or make the yellow blink (rate->faster) as it gets closer to switching to red. Anything. Then again, these are the same tards who install red-light cameras then decrease the yellow time to boost revenue.

Right now I tend to use the countdown timer crosswalk signals (if they are available) to know how long I have before the light starts to change; but this can be distracting (I glance at it when I am further away from the intersection, and count down with it - I don't look at it constantly while I am driving toward the intersection). Plus, sometimes things are arranged where it is "stop" for pedestrians but still "green" for cars going in the same direction (likely for left turners or something), so this method isn't foolproof.

Maybe you could modify your Arduino code to do simulate this idea (do they sell bi-color LED 7-seg displays?)... :smiley:

crOsh,

Maybe you could modify your Arduino code to do simulate this idea (do they sell bi-color LED 7-seg displays?)...

Since I have only been working with the Arduino for a week, I think I'll leave that project to someone else for now.... :o

NetWorm,

In the city, the lights tend to go into hibernation and just blink yellow for everyone about 2-3 am. ::slight_smile:

Go figure, make the street lights confusing just when all the drunks are driving home.... :o

And its worth adding that in some US states, red means stop, green means go, and yellow means go faster

Or as one young lad described it: "Red means stop, green means go, and yellow means mommy slow down, daddy speed up!" :slight_smile:

-Mike

Heh, nice! Also IIRC, Euro signals are horizontal and US signals are vertical(?)

See, now you have to step it up a notch or two and put in the left-hand turn signals, ped crosswalk buttons and hall effect sensors to simulate traffic and control the priority of the state changes. :smiley:

See, now you have to step it up a notch or two and put in the left-hand turn signals, ped crosswalk buttons and hall effect sensors to simulate traffic and control the priority of the state changes.

koyaanisqatsi,

I live in a small town in Wisconsin. Our closest stop light is 22 miles away..... ;D

Anyway, I built the basics for others to build upon and make my design pale in comparison.... O.K., I just don't have the ambition right now...... Really, I'm working on connecting my Arduino to my Roomba Discovery.

By the way, since when does a $1.92 plug end up being almost $10.00 with USPS shipping added???????

Anyway, anyone else hack a Roomba? ::slight_smile:

Dan

Hi Wrox and all,

The sketch you wrote, Wrox, works perfectly and is great in that it is easy to understand and modify! I am a beginner and have been looking for a controller of 4lanes. I developed yours into that but could not add a switch that turns on the yellow lights into flashing mode when needed like when it's late at night.

Guys could you please take a look and help me adding that switch?

thanks,

/* real_us_traffic_lights2.pde
   By: Daniel Wright
   2010.JAN.30         (Modified by Ayad Derbal 2010.Feb.23)
   I kept seeing all these Traffic Light programs on the internet
   and I was real unhappy that they were all European style.
   No one had made a US Traffic light. Well, Here it is!
   Realistic US Traffic Lights without cross walk buttons.
   I am going to work on a model with the Pedestrian cross walk
   buttons next.
   */
int carRed1 = 13; // assign the car1 lights
int carYellow1 = 12;
int carGreen1 = 11;
int carRed2 = 10; // assign the car2 lights
int carYellow2 = 9;
int carGreen2 = 8;
int carRed3 = 7; // assign the car3 lights
int carYellow3 = 6;
int carGreen3 = 5;
int carRed4 = 4; // assign the car4 lights
int carYellow4 = 3;
int carGreen4 = 2;

void setup() {
pinMode(carRed1, OUTPUT);
pinMode(carYellow1, OUTPUT);
pinMode(carGreen1, OUTPUT);
pinMode(carRed2, OUTPUT);
pinMode(carYellow2, OUTPUT);
pinMode(carGreen2, OUTPUT);
pinMode(carRed3, OUTPUT);
pinMode(carYellow3, OUTPUT);
pinMode(carGreen3, OUTPUT);
pinMode(carRed4, OUTPUT);
pinMode(carYellow4, OUTPUT);
pinMode(carGreen4, OUTPUT);

// initialize the lights
digitalWrite(carRed1, HIGH);
digitalWrite(carRed2, HIGH);
digitalWrite(carRed3, HIGH);
digitalWrite(carRed4, HIGH);
delay(4000);
}

void loop() {
digitalWrite(carRed1, LOW);
digitalWrite(carYellow1, HIGH);
delay(1500);
digitalWrite(carGreen1, HIGH);
digitalWrite(carYellow1, LOW);
delay(5000);
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow1, HIGH);
delay(500);
digitalWrite(carYellow1, LOW);
delay(500);
}
digitalWrite(carGreen1, LOW); 
digitalWrite(carYellow1, LOW); 
digitalWrite(carRed1, HIGH); 

delay(2000); // wait 1 second till its safe

digitalWrite(carRed2, LOW); 
digitalWrite(carYellow2, HIGH); 
delay(1500); 
digitalWrite(carGreen2, HIGH);
digitalWrite(carYellow2, LOW);
delay(5000);
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow2, HIGH);
delay(500);
digitalWrite(carYellow2, LOW);
delay(500);
}
digitalWrite(carGreen2, LOW);
digitalWrite(carYellow2, LOW); 
digitalWrite(carRed2, HIGH); 
delay(2000); // wait 1 second till its safe

digitalWrite(carRed3, LOW);
digitalWrite(carYellow3, HIGH); 
delay(1500); 
digitalWrite(carGreen3, HIGH); 
digitalWrite(carYellow3, LOW); 
delay(5000); 
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow3, HIGH);
delay(500);
digitalWrite(carYellow3, LOW);
delay(500);
}
digitalWrite(carGreen3, LOW); 
digitalWrite(carYellow3, LOW); 
digitalWrite(carRed3, HIGH);
delay(2000); // wait 1 second till its safe


digitalWrite(carRed4, LOW); 
digitalWrite(carYellow4, HIGH); 
delay(1500); 
digitalWrite(carGreen4, HIGH); 
digitalWrite(carYellow4, LOW); 
delay(5000); 
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow4, HIGH);
delay(500);
digitalWrite(carYellow4, LOW);
delay(500);
}
digitalWrite(carGreen4, LOW); 
digitalWrite(carYellow4, LOW); 
digitalWrite(carRed4, HIGH); 
delay(2000); // wait 1 second till its safe
}