Traffic Signal / Stop Light Wiring With Arduino Controller

79,375

164

43

Published

Introduction: Traffic Signal / Stop Light Wiring With Arduino Controller

About: Drunk posting ill conceived instructables since 2009.

I always wanted an old traffic signal and finally got one recently.  However, it was very simply wired so that all the lights were fixed on.  What fun is that?  I also wanted to try out an Arduino controller and thought this would be a nice simple project to incorporate it into. 

This Instructable will show you how to wire up an old traffic signal with an Arduino controller to function like a real traffic light.  I used a pretty simple program and controls.  Given the power of the Arduino controller, there are a lot of ways you can customize this.

Step 1: Stuff You Will Need

Obviously you will need an old traffic signal.  I got mine on Craigslist for $40.  It is one of the newer plastic cased ones, but it looks fine from a distance.  I would kind of like an old metal one, but I'll have to upgrade later I guess.

The brains of this thing are going to be an Arduino Uno connected to a relay module. 

Arduino Uno
http://www.amazon.com/Arduino-UNO-board-DIP-ATmega328P/dp/B006H06TVG/ref=sr_1_1?ie=UTF8&qid=1362360128&sr=8-1&keywords=arduino+uno

SainSmart 4-Channel 5V Relay Module
http://www.amazon.com/SainSmart-4-Channel-Relay-Module-Arduino/dp/B0057OC5O8/ref=sr_1_2?ie=UTF8&qid=1362350898&sr=8-2&keywords=RELAY+MODULE
(Note:  This relay is pretty loud.  I can hear it click from across the room.  If anyone has suggestions for something similar that is not as noisy, let me know.)

You will need a power supply (transformer, wall wart, AC/DC adapter) for the Arduino.  I used a 12V 750mA wall wart that I had from some other piece of electronics that had died.  Most 7V to 12 V transformers should work.  You can pick one up at Goodwill for about $2.  Stay away from Radio Shack, they wanted $20-$30 for wall warts!  I am sure someone who knows more about the Arduinos can chime in as to what kind of amperage range you should stay in.  Here's one from Amazon that should work fine:
http://www.amazon.com/Wall-Adapter-Power-Supply-650mA/dp/B003XZSZWO/ref=pd_bxgy_pc_img_y


You will also need some male to female jumpers to connect the Arduino to the relay module (note, I did not have these but wish I did):
http://www.amazon.com/Jumper-Wires-Premium-200mm--Female/dp/B008MRZSH8/ref=sr_1_1?s=electronics&ie=UTF8&qid=1362360630&sr=1-1&keywords=jumper+wire+male+to+female

Note:  If you do not want to mess with the Arduino, there are a couple ready to go traffic signal controllers available online.  I could have gone this route, but I was really wanting to try out the Arduino:
http://www.ecrater.com/p/12018399/micro-3-traffic-light-signal-controller
http://trafficlightwizard.com/3colorsequencerkitforrotationofflashinglight.aspx

A lamp or appliance cord with ground wire

Other materials you will need will depend on the starting state of your traffic signal.  I used some 16 ga wire (for the internal line voltage wiring), solder, sheet metal screws (for securing the Arduino and relay module, and attaching ground wires to the frame), wire nuts (for connecting line voltage wires), epoxy (to secure transformer), heat shrink tubing (to insulate transformer connections).

Tools:

You will need a USB B cable to connect the Arduino to your computer to program it.  If you have a USB printer you should already have one of these.

Wire cutters
Wire strippers
mini flat head screwdriver for relay connections

Other tools you will need will again depend on the initial state of your traffic signal.  I used the following:

Cordless drill (for drilling holes in the case)
Soldering Iron (for wire connections and heat shrink tubing)
Dremel tool with milling bit (cut off some the plastic in the case to make mounting the new components easier)
Eye and hearing protection if you are using power tools.

Software:

You will need the Arduino programming software to upload the code to the Arduino:
http://arduino.cc/en/main/software

Step 2: The Plan

Below is a wiring diagram for the traffic signal.  Hopefully this is pretty clear what gets wired to what. 

Step 3: The Brains

Above is a photo of the Arduino Uno and the relay module with the wiring between the two attached.  I only had male to male jumpers, so I used a Molex connector and my mad soldering skills to make a connector (second photo).  It is probably easier to use male to female jumpers to connect everything or find a 6 pin jumper to use.  The Arduino has all female sockets and the relay module has all male pins.

Step 4: Program It!

If you have not used an Arduino before, see this Instructable by randofo:  https://www.instructables.com/id/Intro-to-Arduino/

Download and start the Arduino programming software if you have not already.  Connect the Arduino to your computer with a USB B cable.

Copy and paste the code the below and upload it to the Arduino.  One the code uploads it should start running immediately on the Arduino.  You should see the indicator lights going on and off on the relay unit and hear the relay switches tripping.

You can make this more simple or complicated if you want.  I have it set up to cycle through 25 normal cycles, switch to blinking red for a few minutes, do 25 more normal cycles, switch to blinking yellow for a few minutes, and then repeat.

//Fzumrk's traffic controller code
 
// name your pins:
int red = 12;
int yellow = 11;
int green = 10;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green, OUTPUT);
}
int  var = 0; //defines and sets initial value for variables used below
int var1 = 0; //defines and sets initial value for variables used below

// the loop routine runs over and over again forever:
void loop() {

// sets initial value for pins so that lights start as "off" 
digitalWrite(green, HIGH);
digitalWrite(yellow, HIGH);
digitalWrite(red, HIGH);

while(var < 25){
  // repeats normal cycle 25 times
  digitalWrite(green, LOW);   // turns the green light on
  delay(20000);               // holds the green light on for 20 seconds
  digitalWrite(green, HIGH);    // turns the green light off
  delay(600);               // slight pause between lights
  digitalWrite(yellow, LOW);  //turns the yellow light on
  delay(4000); //holds the yellow light for 4 seconds (watch out for that red-light camera!)
  digitalWrite(yellow, HIGH); //turns the yellow light off
  delay(600);  //slight pause between lights
  digitalWrite(red, LOW);  //turns the red light on
  delay(20000);  //holds the red light on for 20 seconds
  digitalWrite(red, HIGH);  //turns the red light off
  delay(600);  //slight pause between lights
  var++;}  //adds 1 to variable "var" for repeat count
 
  // after 25 cycles above, the light switches to "power outage mode", flashing red
  delay(600); //slight delay
  var1=0; //resets variable "var1" to 0
  while(var1 < 120) {
    // repeats power outage cycle 120 times - 2 minutes
   digitalWrite(red, LOW);
   delay(600);
   digitalWrite(red, HIGH);
   delay(400);
   var1++;}
var = 0;

//switches back to normal cycle after "power outage" cycle is done
while(var < 25){
  // back to normal light cycle for 25 cycles
  digitalWrite(green, LOW);   // turn the LED on (HIGH is the voltage level)
  delay(20000);               // wait for a second
  digitalWrite(green, HIGH);    // turn the LED off by making the voltage LOW
  delay(600);               // wait for a second
  digitalWrite(yellow, LOW);
  delay(4000);
  digitalWrite(yellow, HIGH);
  delay(600);
  digitalWrite(red, LOW);
  delay(20000);
  digitalWrite(red, HIGH);
  delay(600);
  var++;}
  delay(600);
 
 //switches to "late night cycle" flashing yellow for 2 minutes, similar to flashing red above
 var1=0;
  while(var1 < 120) {
   digitalWrite(yellow, LOW);
   delay(600);
   digitalWrite(yellow, HIGH);
   delay(400);
   var1++;}
   var = 0;
 //goes back to normal cycle at top and repeats forever 
}

Step 5: Power Supply

I converted a wall wart type transformer to a built in power supply by soldering some pig-tails to the wall plug blades and insulating them with heat shrink tubing.  I then hard-wired the transformer to the power cord coming into the traffic signal.  You can always run this wire separate and plug it directly into an outlet if you do not want to covert the transformer like I did.

Step 6: Wire It Up

MAKE SURE THE WALL PLUG IS NOT PLUGGED IN WHEN YOU ARE WORKING ON THE INTERNAL WIRING.  If you don't know to do this, you probably should not be attempting this project.  Anyway, consider yourself warned.  I take no responsibility for accidental electrocutions.

The case for my traffic signal is made of plastic, but there are some metal parts on it that I thought should be grounded.  If yours has a metal case, you should probably ground the case directly. 

I used normal wire nuts for the all of the line voltage wiring connections.  I tinned the ends of the stranded wires with solder before putting on the wire nuts.

Step 7: Run It!

The traffic light's normal cycle:


"Power Outage" mode, blinking red:


The internal workings:

Share

Recommendations

  • Creative Misuse Contest

    Creative Misuse Contest
  • Oil Contest

    Oil Contest
  • Clocks Contest

    Clocks Contest

43 Discussions

I have purchased a second traffic light. The first is controlled manually by a latching relay system. Would like to experiment with an arduino micro controller. What made you choose the Arduino board you did choose? Could you get the same functionality from a less expensive board. This will be my first attempt at Arduino from a kit I bought over a year ago. I realize there are many different versions of the board. Just wondering if there is a cheaper solution.

Thanks,

TRU

3 replies

I just picked one that I saw many other people using in their instructable projects. I am pretty confident you can make this work with a much simpler project board. This barely uses the available functionality of the Uno.

How should I go about selling this bad boy, so another enthusiast can enjoy it

image.jpg

Nice project and very similar to my own in many respects. Mine is automatic although will also be controlled from the web. I notice on your cct diag you are plugging AC directly into the Arduino - do they rectify AC?

Many thanks

D6

Can this be done using a remote type button. I would like to be able to use a sensor somewhat like what is on a garage door opener to switch the light from green to orange to red and back. Grandkids would love it when we come home. What would you suggest?

1 reply

this might be a solution...Hot ! Thunbird New 12v 4 Channel Wireless Remote Control Receiver Momentary Switch https://www.amazon.com/dp/B00BQ842DG/ref=cm_sw_r_other_awd_04bgxbGQKE213

It has been over a year since looking for information here, and almost 2 years since I started on this project. Overall, I did the research bought a couple parts and handed it off to a very willing buddy to make it happen. Here are images of my final product of manual switching of lights with no controller. If you want more information go here ...

http://www.diychatroom.com/f18/manual-button-contr...

Good luck and thanks to those who shared information

TRU

buttons.jpgoff.jpgbuttonswired.jpgrelays.jpg

Anybody help me? I have a traffic light and one of those halloween sensor pads. I want my traffic light to stay green when powered on and switch to yellow when the pad is pressed. Then switch to red when the pad is pressed again. Then green.

1 reply

I'm not sure what a halloween sensor pad is, but I am guessing it is a momentary switch. If that is what it is you should be able to incorporate it into the arduino.

Here is a quick tutorial showing how to us a momentary switch with arduino:

https://www.instructables.com/id/How-to-use-a-Push-Button-Arduino-Tutorial/

anybody know how to wire with 3 momentery switches instead of arduino?

8 replies

Maybe? Let me know if this is what you are trying to do:

3 Buttons, push one for green, push another for yellow, push another for red? The other lights go off when you push a different switch?

Just to be clear, if you used momentary switches, the lights will only be on while you are holding the button down. If you want each switch to act like an on/off toggle, that is a different configuration.

Hmm... I thought that momentary switches in combination with a relay board would allow for sequence you named originally?

A momentary switch is only on while being held down. The relay is only switched on while is receiving current on the signal side.

I thought about how to make this work the way you want, but I am not sure how to accomplish it without using a Arduino or other controller. With the Arduino, you should be able to program it to switch on and off the appropriate relays when it received a momentary signal from one of the switches.

Thanks for your time on this. Greatly appreciated. My original venture was this post where I discovered from others the use of relays.

http://www.diychatroom.com/f18/manual-button-controls-traffic-light-197259/

Never went any further than the thread as it was beyond my comprehension. Once I discovered the relay boards I thought it might be a solution. Perhaps it is the "latching relay" that is needed? Anyways, until I find a doable solution this is my current solution, a 4 position rotary switch.

http://www.amazon.com/gp/product/B009IS73I2/ref=oh_aui_search_detailpage?ie=UTF8&psc=1

Not a bad solution, but a little clunking moving through lights. Again... thanks for your time and wisdom.

I think user "mpoulton" at the linked site figured it out. I did not know about latching relays, but it sounds like they should work with using momentary switches like you are trying to do. I'll quote his text and picture here in case anyone else is trying to figure this out.

The thing I am not sure about is where to get the three pole, double throw relays. You may want to check in one of the electronics forums on here to see if someone who knows more than me can find you the appropriate part. I think "3PDT latching relay" is what you need to look for, but I am not sure on the exact specs you want. You may want to set it up the switch circuit with all low voltage relays and tie the outputs on them to basic low voltage to high voltage relays to control the line level current going to the lights.

Just based on what I am comfortable working with and what I am guessing all of the relays will cost is that you, is that you could buy an Arduino or other controller and program it to do the same thing for less money and trouble.

"The relay setup is not terribly complicated, but you'll need to really
understand how it works to do it successfully. There are numerous
possible relay configurations that would work. I'd start with three
relays, each 3-pole double-throw. Each relay controls one light. The
button for each light activates the relay coil, which is wired through
one pole of each of the other two relays (normally-closed), and latches
because you connect the relay coil to the light also. Then when either
of the other two relays are activated, it breaks the coil circuit for
the other relay so that it deactivates. This gives you three latching
relays, where each one unlatches the others."

schemeit-project.jpg

Wonder if this board kit works the same as those relay boards designed for arduino. https://www.parallax.com/product/27114 If so, no need for the board as the video here https://www.youtube.com/watch?v=0oXl7_hj1o4 explains how to "cleverly wire" a two relay board for three lights. If the parallax board is needed, then there is the down side of paying for a board that you have to build. Hmmmm.....?