Two way traffic lights with arrows simulation

21
April 1, 2016 By: Samuel Vidal My Electronic Engineering Senior Project: Two Ways Traffic Lights and Arrows Signal Simulation Warning: This is a demonstration of a traffic light simulation. If you (the reader), decide to attempt this project, it is recommended that you have basic knowledge of how electricity works. In this case, I am using 120V for this simulation, which can be dangerous for a person not having knowledge. When working on electrical objects/equipment, always disconnect the power. You can also adapt the traffic lights to use less power with a power supply (12V or 24V) and smaller light bulbs or LED’s. The traffic light: For my Electronic Engineering Senior Project, I wanted to simulate a traffic light, so I did a research on the internet and found this idea from this website, by fzumrk: http://www.instructables.com/id/Traffic-Signal-Stop-Light-Wiring-with-Arduino- Co/?ALLSTEPS . I found this project to be a cool, simple, and gorgeous project. The guy adapted a microcontroller (Arduino) and a relay (SaintSmart) on an authentic traffic light fixture, simulating a one way traffic light and power outage flashing lights. Since I have worked with the Arduino’s microcontrollers before, I knew it would be an easy project for me to accomplish.

Transcript of Two way traffic lights with arrows simulation

Page 1: Two way traffic lights with arrows simulation

April 1, 2016

By: Samuel Vidal

My Electronic Engineering Senior Project:

Two Ways Traffic Lights and Arrows Signal Simulation

Warning: This is a demonstration of a traffic light simulation. If you (the reader), decide to attempt this project, it is recommended that you have basic knowledge of how electricity works. In this case, I am using 120V for this simulation, which can be dangerous for a person not having knowledge. When working on electrical objects/equipment, always disconnect the power. You can also adapt the traffic lights to use less power with a power supply (12V or 24V) and smaller light bulbs or LED’s.

The traffic light:

For my Electronic Engineering Senior Project, I wanted to simulate a traffic light, so I did a research on the internet and found this idea from this website, by fzumrk: http://www.instructables.com/id/Traffic-Signal-Stop-Light-Wiring-with-Arduino-Co/?ALLSTEPS . I found this project to be a cool, simple, and gorgeous project. The guy adapted a microcontroller (Arduino) and a relay (SaintSmart) on an authentic traffic light fixture, simulating a one way traffic light and power outage flashing lights. Since I have worked with the Arduino’s microcontrollers before, I knew it would be an easy project for me to accomplish.

However, for my project, I had another idea in mind. I wanted to do a simulation using a two way traffic light system with arrows (8 lights) and a push button switch light activation. At first, I wanted to use an authentic traffic light fixture. Unfortunately, that was not possible. I went searching on websites like ebay, Amazon, and Craig’s list to buy a used traffic light fixtures but the items were extremely overpriced ($195.00 and +), plus shipping ($65.00).

My second options was to write a letter to the DOT and public works department explaining the situation and if it was possible for them to sell or donate an unused stored traffic light fixture at a low price to use for my project, but unfortunately I never got a response from them. In the end, the only available item I could use to simulate my project (suggested by my professor) was using two stack lights from our robotics classroom.

Page 2: Two way traffic lights with arrows simulation

Fig1. Stack lights mounted on traffic light control box unit

Although in this case, the stack lights worked fine for the project (since it has the usual colors for a traffic light), I was not happy with it. I still wanted to simulate something that really looked like a traffic light, that people would be able to recognize it as a traffic light simulation. This is when a few days later, I was at Lowes hardware store and in the lighting aisle section I saw these recessed light housings and I immediately came up with another idea; this was the perfect item I needed for my traffic light simulation.

Fig2. Recessed Light Housing

My idea consisted in buying three light housings and installing them vertically, attached by the metal rail using screws, so it would resemble a traffic light fixture.

Page 3: Two way traffic lights with arrows simulation

Fig3. Traffic light with recessed light housing

Then to make it look more realistic, I painted the housing (chassis only) with amber spray paint.

Fig4. Housing painted with amber spray paint

Fig5. Recessed light painted

I used three 25 Watts light bulbs (red, yellow, green). For each light slot, I wanted to use plastic clear lids (takeout containers) as covers. However, there were some concerns and questions about the risk of the plastic lid getting burn or melt by the heat generated from the light bulb.

Page 4: Two way traffic lights with arrows simulation

I did a research on these microwavable lids, and I found out they can resist heat temperature up to 250o degrees F. Then I performed some temperature test on a 25 watts light bulb (using a thermometer directly to the light bulb), and it took an hour for the light bulb to reach a temperature of 146o F. After an additional hour, the temperature remained the same. In this case, the longest a light bulb would stay ON would be less than 35 seconds, which the light bulb will not have enough time to reach that amount of temperature. I also performed a second test by placing the thermometer near the light bulb, without touching it and in the same amount of time, the temperature reached about 79o F.

To create the arrows, I placed tape in a shape of an arrow on top of the lids, and paint the lids with black spray paint. When the paint dried, I removed the tape from the lids. However, the lids are optional items if you want to add them.

I started to wire the light housings using color coded plugs to identify each lights and its color when connecting and disconnecting the light housing from the control box unit (CBU). The male plugs were installed to the light housing and the female plugs to the control box unit for safety, to avoid the danger of an electrical shock when the control box is connected to power, which uses 120V.

Fig6. Wiring of light housing

Page 5: Two way traffic lights with arrows simulation

Fig7. Color coded power plugs

I also installed visors around each light, using small screws. You normally see visors on traffic lights. I used aluminum dryer vent extenders since it already had that round shape and cut it in size of 4 inch wide and 12 inch long, and painted them with amber spray paint.

Fig8. Traffic light visor

Page 6: Two way traffic lights with arrows simulation

Fig9. Installing a visor on the traffic light

The Control Box Unit (CBU)

The CBU is the metal box where I installed the microcontroller and the two relays that makes the connections possible between the box and the light housing. The microcontroller (Arduino) is the brain of the operation. This is where I programmed and uploaded the code data into the micro-controller to control the light sequence. The microcontroller is connected to a 4 channel relay, since the traffic light uses 120V; the microcontroller can’t handle this type of voltage (works with 5V). In this case, I use the relays to be able to power up the lights. Here is a schematic diagram of the CBU.

Page 7: Two way traffic lights with arrows simulation

Fig10. Schematic diagram of the Control Box Unit (two way traffic light with arrows)

To learn how to use a push button switch with Arduinos micro-controllers, go to Arduino website at:http://www.arduino.cc/en/Tutorial/Button

Page 8: Two way traffic lights with arrows simulation

Fig11. View of the Control Box Unit

Materials list and cost: (Only for 1 traffic light system)

Item Picture CostArduino UNO R3 Micro-controller

$24.77

(Amazon)

SainSmart 4-Channel Relay Module $11.90

(eBay)

Page 9: Two way traffic lights with arrows simulation

Wall Adapter Power Supply - 9V DC 650mA $6.50

(eBay)

50 PCS Jumper Wires Premium 200mm M/F Male-to-Female $8.00

(eBay)

Appliance cord or extension cord(Suicidal Cord) $6.49

(Lowes)

Recessed Light Housing $7.67 x 3 = $23.01

(Lowes)

Colored lights$1.89 x 3 = $5.67

(Walmart)

Spray paint

$4.88

(Lowes)

Dryer vent extender$3.45

(Lowes)

Misc. Wire, electrical caps connectors, zip ties, screws

$18.00

(Lowes)The Total Cost $112.67This material list cost is based on most common retail/website stores. However, these items can be found at a lower price at other stores and websites.

Page 10: Two way traffic lights with arrows simulation

Traffic light final view

Programming code for Arduino microcontrollerFor information about Arduino micro-controllers and how to learn to program, go to Arduino website at: www.Arduino.cc

One way traffic light mode program code (1 traffic light system)Since there is already a program code for a single light sequence mode, I see no need to re-write the code. You can find the code at by fzumrk: http://www.instructables.com/id/Traffic-Signal-Stop-Light-Wiring-with-Arduino-Co/?ALLSTEPS#step4

******************************************************************

Page 11: Two way traffic lights with arrows simulation

Two way traffic lights with arrows sequence mode program code (two traffic light system)

//2 Way traffic light arrow flashing automatic sequence

// In order for your traffic light to work properly with this code// make sure you connect the lights to the proper pins and relay// channels as shown in schematic. Otherwise, the lights will// not light up in the proper sequence.

//Traffic light 1 includes (red, yellow, green) lights//Traffic light 2 includes (red, yellow, yellow arrow, green, green arrow) lights

// declare variables and pins. According to schematic, pins connections are:int rLight1 = 12; //arduino microcontroller(pin12), SainSmart relay 1(IN3, K3), Traffic red light 1int yLight1 = 11; //arduino microcontroller(pin11), SainSmart relay 1(IN2, K2), Traffic yellow light 1int gLight1 = 10; //arduino microcontroller(pin10), SainSmart relay 1(IN1, K1), Traffic green light 1int rLight2 = 9; //arduino microcontroller(pin9), SainSmart relay 2(IN3, K3), Traffic red light 2int yLight2 = 8; //arduino microcontroller(pin8), SainSmart relay 2(IN2, K2), Traffic yellow light 2 int gLight2 = 7; //arduino microcontroller(pin7), SainSmart relay 2(IN1, K1), Traffic green light 2int yArrow = 6; //arduino microcontroller(pin6), SainSmart relay 1(IN4, K4), Traffic yellow arrow light 2int gArrow = 5; //arduino microcontroller(pin5), SainSmart relay 2(IN4, K4), Traffic green arrow light 2

void setup() { // This initialize pin as an output. pinMode(rLight1, OUTPUT); pinMode(yLight1, OUTPUT); pinMode(gLight1, OUTPUT); pinMode(rLight2, OUTPUT); pinMode(yLight2, OUTPUT); pinMode(gLight2, OUTPUT); pinMode(yArrow, OUTPUT);

Page 12: Two way traffic lights with arrows simulation

pinMode(gArrow, OUTPUT);}//These varialbe are use for loop countersint var = 0; int var1 = 0; int var2 = 0;int turnL = 0;

void loop() {

// Sets all lights outputs as HIGH. (HIGH = Off), (LOW = ON) digitalWrite(gLight1, HIGH);digitalWrite(yLight1, HIGH);digitalWrite(rLight1, HIGH);digitalWrite(gLight2, HIGH);digitalWrite(yLight2, HIGH);digitalWrite(rLight2, HIGH);digitalWrite(yArrow, HIGH);digitalWrite(gArrow, HIGH);var = 1;

while(var == 1){ // It will repeat code forever as long var equals 1. // You can alter the number of times it loops by changing the variable //var will be less than, say 2 or 10, etc, and setting var++ at the end of code. digitalWrite(gLight1, LOW); //green light on traffic light 1 is ON digitalWrite(rLight2, LOW); //red light on traffic light 2 is ON delay(10000); // It waits for 10 seconds before proceding to next code digitalWrite(gLight1, HIGH); // green light on traffic light 1 is OFF delay(600); // Its a small pause between ON/OFF digitalWrite(yLight1, LOW); //yellow light on traffic light 1 is ON delay(5000); //it waits for 5 seconds before proceding to next code digitalWrite(yLight1, HIGH); //yellow light on traffic light 1 is OFF delay(600); //small pause between ON/OFF digitalWrite(rLight2, HIGH); //red light on traffic light 2 is OFF digitalWrite(rLight1, LOW); //red light on traffic light 1 is ON digitalWrite(gLight2, LOW); //green light on traffic light 2 is ON digitalWrite(gArrow, LOW); //green arrow light on traffic light 2 is ON delay(10000); //it waits 10 seconds before proceding to next code digitalWrite(gArrow, HIGH);//green arrow light on traffic light 2 is OFF

Page 13: Two way traffic lights with arrows simulation

delay(600);//small pause between ON/OFF digitalWrite(yArrow, LOW);//yellow arrow light on traffic light 2 is ON delay(5000);//it waits for 5 seconds before proceding to next code while(var2 < 10){//activate yellow arrow yield turn mode while traffic light is on green mode turnL++; if(turnL == 10){ digitalWrite(gLight2, HIGH); digitalWrite(yArrow, LOW);//yellow arrow light on traffic light 2 is ON delay(600);//small pause between ON/OFF digitalWrite(yArrow,HIGH);//yellow arrow light on traffic light 2 is OFF delay(400);//small pause between ON/OFF digitalWrite(yLight2, LOW);//yellow arrow light on traffic light 2 is ON } else{ digitalWrite(yArrow, LOW);//yellow arrow light on traffic light 2 is ON delay(600);//small pause between ON/OFF digitalWrite(yArrow,HIGH);//yellow arrow light on traffic light 2 is OFF delay(400);//small pause between ON/OFF } var2++;}//adds 1 to variable var2 = 0;//resets variable to 0 turnL = 0;//resets variable to 0

while(var2 < 5){//regular sequence between yellow arrow and yellow light turnL++; if(turnL == 5){ digitalWrite(yLight2, HIGH);//yellow light on traffic light 2 is OFF digitalWrite(yArrow, LOW);//yellow arrow light on traffic light 2 is ON delay(600);//small pause between ON/OFF digitalWrite(rLight1, HIGH);//red light on traffic light 1 is OFF digitalWrite(rLight2, LOW); //red light on traffic light 2 is ON digitalWrite(gLight1, LOW);//green light on traffic light 1 is ON digitalWrite(yArrow,HIGH);//yellow arrow light on traffic light 2 is OFF } else{ digitalWrite(yArrow, LOW);//yellow arrow light on traffic light 2 is ON delay(600);//small pause between ON/OFF digitalWrite(yArrow,HIGH);//yellow arrow light on traffic light 2 is OFF

Page 14: Two way traffic lights with arrows simulation

delay(400);//small pause between ON/OFF } var2++;}//adds 1 to variable var2 = 0;//resets variable to 0 turnL = 0;//resets variable to 0 delay(5000);// It waits for 5 seconds before proceding to next code var = 1;//resets var variable to 1 } }

******************************************************************************Switch Button traffic light activation (2 traffic lights systems)

//by Samuel Vidal//include a Switch Button traffic light Activation (does not include arrows)

// In order for your traffic light to work properly with this code// make sure you connect the lights to the proper pins and relay// channels as shown in schematic. Otherwise, the lights will// not light up in the proper sequence.

//Traffic light 1 includes (red, yellow, green) lights//Traffic light 2 includes (red, yellow, yellow arrow, green, green arrow) lights

// declare pins and variableconst int buttonPin = 2;// the number of the pushbutton pinconst int ledPin = 13; // the number of the LED pinint r1 = 12; //arduino microcontroller(pin12), SainSmart relay 1(IN3, K3), Traffic red light 1int y1 = 11; //arduino microcontroller(pin11), SainSmart relay 1(IN2, K2), Traffic yellow light 1int g1 = 10; //arduino microcontroller(pin10), SainSmart relay 1(IN1, K1), Traffic green light 1int r2 = 9; //arduino microcontroller(pin9), SainSmart relay 2(IN3, K3), Traffic red light 2int y2 = 8; //arduino microcontroller(pin8), SainSmart relay 2(IN2, K2), Traffic yellow light 2int g2 = 7; //arduino microcontroller(pin7), SainSmart relay 2(IN1, K1), Traffic green light 2int yA = 6; //arduino microcontroller(pin6), SainSmart relay 1(IN4, K4), Traffic yellow arrow light 2

Page 15: Two way traffic lights with arrows simulation

int gA = 5; //arduino microcontroller(pin5), SainSmart relay 2(IN4, K4), Traffic green arrow light 2int var = 0; //sets var to 0

int buttonState = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); pinMode(r1, OUTPUT); pinMode(y1, OUTPUT); pinMode(g1, OUTPUT); pinMode(r2, OUTPUT); pinMode(y2, OUTPUT); pinMode(g2, OUTPUT); pinMode(yA, OUTPUT); pinMode(gA, OUTPUT); digitalWrite(r1, HIGH); digitalWrite(y1, HIGH); digitalWrite(g1, LOW); digitalWrite(r2, LOW); digitalWrite(y2, HIGH); digitalWrite(g2, HIGH); digitalWrite(yA, HIGH); digitalWrite(gA, HIGH); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); //Using a normally closed momentary push button switch, "if buttonState" condition should be set "LOW" //Using a normally open momentary push button switch, "if buttonState" condition should be set "HIGH"

Page 16: Two way traffic lights with arrows simulation

//This code will not work unless you follow these suggestions.

//This code is set using a normally closed switch. This code only works pressing the switch button //momentary. Do not press the button continuously, while code is executing. When the code loops back, //no change will occur and var will remain 1, which will make the code repeat the same //light pattern, instead of the secondary pattern, altering the lights sequence. if (buttonState == LOW) {//buttonstate condition is set LOW, since is a normally closed switch var++; if(var == 1){ digitalWrite(g1, HIGH); delay(600); digitalWrite(y1, LOW); delay(3000); digitalWrite(y1, HIGH); delay(600); digitalWrite(r1, LOW); digitalWrite(g2, LOW); digitalWrite(r2, HIGH); }

if(var == 2){ digitalWrite(g2, HIGH); delay(600); digitalWrite(y2, LOW); delay(3000); digitalWrite(y2, HIGH); delay(600); digitalWrite(r2, LOW); digitalWrite(g1, LOW); digitalWrite(r1, HIGH); var = 0;//resets var to 0 } if(var > 2){// prevents the code of getting out sequence by resetting // var to 0, if switch is press more than 2 times. var = 0;//resets var to 0 }

Page 17: Two way traffic lights with arrows simulation

} }