Instructables
At the place I work, we use xymon to monitor of our servers. All of the services monitored are important, but we wanted a separate indicator to simply show the overall health of the most critical systems. Furthermore, we came up with the following criteria:
  1. We wanted this visible to everyone whether or not they were near a web browser or even a monitor.
  2. We wanted it to preserve the "red/yellow/green" status's xymon uses.
  3. We wanted it to be stand alone, not requiring a separate computer (we already have one running a widescreen monitor elsewhere for that).
  4. We wanted it to look good and be fun.
After a little brainstorming, we decided a stoplight equipped with an ethernet enabled arduino would do the trick and I set out to build it.

This article will be of particular interest to you if any of these apply:
  • You have a stoplight that you wish could be controlled by a web browser.
  • You would you like to learn how to safely control 120volt lamps from an arduino.
  • You would you like to learn how to turn an ethernet shield equipped arduino into a simple web server to control outputs.
  • You have a "red/green" monitoring system that you would like to have a visible, fun, hard-to-overlook physical component.

I'd sure love to have my own laser cutter. Please see the notes at the end for thoughts on how I would use one, and if you like this article, please rate it and vote for it in the laser challenge.
 
Remove these adsRemove these ads by Signing Up

Step 1: What you need

Picture of What you need
DSCN2218.JPG
Below is a list of everything needed to buy if building from scratch. Don't let the $126 electronics bill scare you; there are a number of ways to save by scrounging and foregoing some cosmetic items. Aside from the Stoplight, the largest costs are the arduino and the Ethernet shield. Obviously if you have either of these items already, this project will cost considerably less (-$30 and -$44.44 ). The two enclosures are not strictly needed, particularly if you are going to stuff everything into a stop light (-$17.46 ). Any 9 volt power supply that can power the arduino can work. There is no need to buy this expensive one if you have one laying around (-$16.68 ). And finally, the ribbon cable (-$3.22 ) can be replaced by any 6 conductor cable or even just 6 wires, and probably doesn't need to be 4 feet depending on where you put the arduino and the power circuit.

You will need the following tools:
  • Soldering iron
  • Dremel or other tool to cut and shape the enclosures if needed
  • Diagonal cutters
  • Hot glue gun (optional)
  • Vice or Helping Hands to hold the board while soldering (optional, but recommended)
  • Multimeter (for testing the circuit before applying live power)
  • Wire wrap tool (optional)

Electronics (Prices in US $ from mouser.com)
4- 1K resistor -- 4 X $0.06 = $0.24
1- arduino -- $30.00
1- ethernet shield -- $44.44
1- arduino enclosure -- $13.33 (optional)
4- NPN Transistors 2N3904 -- 4 X $0.02 = $0.08
4- Diodes 1N4004 -- 4 X $0.06 = $0.24
6- break off headers from 32 pin strip -- $0.66 (Optional, and a strip of 36 is 30 more than needed for this project)
1- 9 pin ribbon cable -- 4 X $0.64 = $2.56 (4 feet, strip off 3 extra conductors and trim to size)
1- 3 X 2 row break off headers from 10 X 2 strip -- $0.65 (7 more than needed, break of 3 columns)
1- 9 volt power supply -- $14.30 (any 9 volt power supply should work)
1- power cord for 9v power supply -- $2.38 (the power supply I ordered didn't come with a cord!)
1- screw terminal block with 6 positions -- $1.00
1- 2x3 socket for ribbon cable -- $0.66
1- protoboard and enclosure (BusBoard KIT-1593L-BK) -- $9.13
4- 9 volt relays (fujitsu lz-9HE) -- 4 X $1.85 = $7.40
4- 1 Kohm resistors -- 4 $0.04 = $0.24
total = $126.83


Other materials:

For testing and hacking the following may be desirable, but are strictly optional:
  • Breadboard
  • Resistors (180 ohms each will do)
  • One each of a Red, Yellow and Green LED

You can order all the mouser items from this project list, or start with that list and subtract anything you don't need. Mouser apparently didn't like all the traffic going right to their shopping card and deleted this project without notice. I'll be updating with actual part numbers later. If you are starting from scratch, make sure you add supplies like solder and wire. As of this writing, mouser does not carry the circuit breaker or stop lights.

Stop lights can found on ebay or on the side of the road after a really good storm*.

* Not really, but you can find them on ebay.

Step 2: Program Arduino and set up ethernet shield

This step can obviously be done later, but if you have the arduino set up as a web server with the control code first, you will be able to test your relay circuit as soon as it is ready. 

You can extract the arduino sketch from the attached "stoplight.zip" file or Download the latest version from http://code.google.com/p/stopduino/.  Open the stoplight.pde file in the arduino IDE and make the following changes before uploading to your arduino:
  1. Because the stoplight will serve as a server and needs to have a non-changing IP address, the IP address is hard coded in the sketch.  You will want to change the line that says "byte ip[] = { 192, 168, 119, 177 }; " to match the IP address you want to assign the stoplight.  Note that the quads that make up the IP address are separated by commas not dots.  This is because the IP address is stored as an array of 4 bytes, each of which is one of the bytes of the IP address.
  2. Do the same thing for the "byte mac[] " line, substituting the MAC address of your ethernet shield.  It should be printed on it somewhere.
  3. Change the "char secret[] " array to be whatever password you want to use.
  4. Change the number in the "EthernetServer server(####) " line to be whatever port you want the server to listen on.  Normally this would port 80.
Program the arduino with your modified sketch, attach the ethernet shield to the arduino, plug it into your network, and then open up a browser window to http://<IP you put in>:<port you put in> or just http://<IP you put in> if you chose port 80 as the port.

Ideally, you should have DNS set up for the stoplight server IP, so you can refer to it as something like http://stoplight.example.com but IP addresses work just as well.

After connecting you should see a simple web page that shows you the current status of each of the lights, complete with check boxes and a place to put your password to change each of them.

If you see the web page appear at all, you will know that your ethernet shield is working, and your arduino is now a web server, even if you can't see it affecting the outside world yet.

Watching the check boxes change without seeing the arduino do anything is pretty boring, so see the next step for an optional test rig you can build for instant (or at least sooner) gratification.

Step 3: Build optional test circuit

This step is not required, but as noted in the previous step, it's a lot easier to troubleshoot problems with the arduino and the code if you set the web server part up first.  But then you need some way to see if it's working.

A few LEDs, some resistors, a breadboard and some jumper wires are all that is needed to set up a test bed for the web server part of the project.  Soon you will have the all important blinky lights essential to any electronics project.

In the completed circuit, each of the four outputs (Red, Yellow, Green and the optional auxiliary output) will be turned on and off by controlling pins 14-17.  While there are no pins labeled 14-17 on the arduino, it does allow the analog pins to be used as digital pins, numbering where digital pin 13 leaves off.  So pin A0 can be treated as pin 14, A1 as pin 15, etc.

To simulate the relays that will control the lights being turned on by the arduino, an LED can be wired in place of each channel.  For each color do the following steps:

  1. Run a jumper wire from the associated pin to a 180 ohm resistor.
  2. Connect the other end of the resistor to the anode (positive, long wire) of an LED.
  3. Connect the cathod (negative, short wire or flat side) of the LED to the ground line.
  4. Connect the ground line to one of the arduino ground (GND) pins.

Repeat steps 1-3 for each of the other control pins.

As soon as the power it applied to the arduino, all three should start blinking, until you set their behavior with the web page.  This is to alert on a power outage.

If all is right, you will be able to see the lights turn on and off as you control them from the web page, as described in the previous step.

You can stop here if all you want to do is control LEDs from a web browser.

Step 4: Create the relay control circuit (theory)

Picture of Create the relay control circuit (theory)
stoplight-combined.png
This section can be skipped if you don't care WHY the circuit works, or if you already understand how relays and transistors work.

The arduino can directly power LEDs because the voltage needed to light them is less than the 5 volts the arduino can put out. But the lamps in a standard US stoplight use 120 volts and are AC. Controlling them from an arduino requires additional circuitry to allow the 5 volt control pins to safely switch on the 120 volt AC lamps without ever directly touching them.

This can be accomplished via relays. A relay is combination of a magnetic switch and an electromagnet. Current flowing through the electromagnet's coil creates a magnetic field that forces the nearby switch to open or close. So large currents can be switched on and off by smaller currents flowing through one part of the relay without directly being part of the larger currents circuit.

I wasn't able to find reasonably priced and sized relays that could control 120 volts from 5 volts, so I used 9 volt relays instead. This leads to a similar problem in that arduino STILL can't control the 9 volt portion of the circuit directly. Fortunately, the gap isn't nearly as dangerous, and transistors can be used to switch the 9 volt relay currents using 5 volt arduino pins. Since the arduino in this project is powered by a 9 volt adapter, we can use the same power source to power the relays.  To do this we can pull 9 volts off of the VIN pin on the arduino. The VIN pin exposes whatever current is used to power the arduino, unlike the 3.5 and the 5 volt pins which are the power after it has been regulated to what the arduino needs internally.

The two diagrams below show how the three different voltages can live in the same device. Click the "i" in the upper left corner of each of them to access the full sized (and not fuzzy) versions.

Each of the four control lines control a lamp or outlet as follows. I'll use the red light to illustrate:
  1. When the control pin is turned on, current is allowed to flow from RED-DC (pin 14) through a resistor into the base of a transistor.
  2. As the 5 volt current flows from the base to ground via the transistor's emitter, this "switches on" the transistor. This allows current to flow from the 9 volt VIN pin on the arduino through the relay's coil and into the transistor's collector; eventually to exit via the emitter to ground.
  3. As current flows though the relay's coil, an electromagnetic field is created and the switch in the relay is drawn closed with a satisfying "click". 120 volts flow through this switch and light the red lamp.
  4. When the control pin is turned off, the 9 volt current stops flowing through the transistor, the electromagnetic field collapses and the relay clicks back off. The diode is in place to protect the transistor from the sudden flood of reversed current pushed back across the contacts of the coil.

The next steps will discuss creating this circuit.

Step 5: Create the relay control circuit (low voltage half)

Picture of Create the relay control circuit (low voltage half)
IMAG0086.jpg
schematicv1.4.png
Because of time constraints, I created this on protoboard using a variety of different techniques.  This worked well enough, but it would have been much easier if I had had time to have the circuit printed. If for no other reason, printed boards are more fun to solder.

Even though I did not have the circuit printed, I did lay it out in eagleCAD so I would know if the parts would fit in the protoboard and enclosure I was preparing to order.  The attached zip file includes the schematic and the board layout.  Please note, the board layout has never been tested.  I believe it will work because I followed the layout when prototyping, but you can never be sure until you set the printed result. Instructables user nickbart successfully printed the board and documented the results on his blog, so you can safely have it printed.

If you choose to have the board printed, this step is fairly simple.  Insert all the components through the top as shown in the layout and solder each of them.  You then are ready to move onto the next steps.

If you choose to do it by hand on protoboard, here are the steps I took to freeform the layout.
Do all of these with the circuit diagram handy to check your work.
  1. Print out the board layout, showing both the top and bottom copper layers, as well as the labels.
  2. Cut along the outside lines until you have a layout the same size as the board.
  3. Tape the paper layout to the protoboard on the side without copper.
  4. Lay out the relays and other components using the circuit diagram to show you what needs to connect to what.  You should lay out the relays, the 6 pin header and the power block as shown on the layout, but when it comes time to add the transistors, resistors and diodes in some cases it makes sense to place them in other places, to be near where they connect.  That's because laying out for a printed board has different placement constraints.  On a printed board component don't usually need to be near another one, but there are only two planes (top and bottom) to run the traces.  But when running your own wire, you can cross as many wires as you like.  At the same time, each time you can place component right by the pads it needs to connect to, you can skip running a wire entirely.
  5. Where possible, place component leads next to each other.  This will allow you to make solder bridges across the copper pads and save running a wire.  For example, the collector of each transistor and one end of each diode connect to one of the relay pins, so where there is room, you can place them all adjacent to each other and solder them together, possibly twisting the leads together and cutting them off later.  DO NOT CUT ANY LEADS until you have accounted for everything that needs to connect to them.  In particular, you will need to leave leads out if you are planning to use wire wrapping techniques.
  6. For the 5 volt parts I used wire wrapping to connect to the leads of the resistors and transistors.  If you don't have wire wrap wire and a way to attach them, you can use the same 22 gauge wire that you will use for the other parts of the circuit.  Using wire wrap allows you to run a very fine wire directly across the bottom of the circuit.  Strictly speaking, wire wrapping should be done with special square posts instead of the round leads that the resistors have, so after they are attached, they should be finalized with a small blob of solder to keep them on.
  7. Where a thicker wire needs to be run (for paranoia's sake I used 22 gauge wire for the 9 volt parts) run them across the top and treat them like other component.  That is, poke them through holes in the protoboard near where you want to connect, bend the wire over to connect to the component, and then solder.
Leave the 120 Volt connections unconnected until after the next two steps.

Step 6: Create the connecting cable

IMAG0104.jpg
IMAG0106.jpg
Space inside the stoplight is at a premium. The relay control circuit probably won't fit in the same lamp housing as the arduino, or you may want to keep the arduino outside the stoplight.  In either case a cable to connect the six pins on the relay circuit needs to be constructed.

Cut the six wire ribbon cable to the desired length, leaving enough length to route around anything in the way in the light, plus a little extra.  I was unable to find a 6 wire cable, so I got a length of 9 wire cable and stripped off three conductors.  Make sure you leave the colored wire on your cable if possible, you will use it to know which side is which later on.

Place the ribbon cable in the socket and squeeze it shut with a vise.  It is possible to crimp it with pliers, but it's also very easy to ruin the socket that way.  If available, a vise is greatly preferred.

For the other side, you will need to solder the wires to male pins to plug into the sockets on the arduino.  Because of the gap between the power pins and the analog pins, you will need to break off a set of two pins and another set of 4.  The easiest way to solder the wires on to the pins is to first plug the pins into the sockets on the arduino.  This lets the arduino act as a holder for the pins, requiring you to only have three hands to hold the wire, solder and soldering iron.

If you don't have three hands, you can first solder a blob of solder onto each pin.  Then tin each of the bare wires with a bit of solder.  To connect the wire, you can just touch it and the soldering iron to the blob of solder on each pin.

Make sure you connect the power line to the right pin on the arduino, referring to the picture.  If you have a marked wire on your cable, use that one.  The next wire over goes to ground, the two of them being twisted.  The remaining four wires go to analog 1-4 (pins 14-17).

If you are using the Arduino/Ethernet enclosure, you will find that the case will no longer close, as the cable is now in the way.  GENTLY bend the pins over 45 degrees, and then band the headers slightly as well.  This will allow the case to to fit.

Step 7: Connect arduino to relay circuit

Plug the ribbon cable into the 6 pin header on the relay circuit, making sure to line up the power line to pin 1. Pin 1 will always line up to one of the wires on the edge of the ribbon and hopefully the colored one if you have it. Use a multimeter to make sure the cable is wired correctly.

Plug the power cord and ethernet cable into the arduino. Use a web browser to test as described in step 2. If everything is connected properly you will hear the relays click as you turn them on and off.

If you can make all four relays click on and off, it's time to move onto the next step, finishing up the control circuit by wiring up the 120 volt portion.

Step 8: Wire the 120v part of the circuit

IMAG0109.jpg
IMAG0110.jpg
IMAG0111.jpg
Now that you know the relays can be controlled, it is time to wire up the 120 volt part of the circuit.  If you printed out the board, this step is already done.  If you are doing it by hand, you have a few more wires to run.

Whenever possible, just poke the wires through the top like all the other components.

Because of the placement of the connections on the relays, and the tight squeeze, this is not always possible.  When this happens, run the wire to the nearest edge before routing over the top.  This will allow you to use the relays for strain relief and minimize the number of times you have to solder a wire directly to a component, plus help insure all the bits of the 120 volt part are as separated as possible in this small space.

I used a different color wire for the "hot" and control connections to be extra sure I didn't mix up the 120 volt parts with any of the control circuitry.

After this is done, you can use a multimeter to test connectivity between the hot screw and the screws for each of lamps.  There should be no continuity when the lamps are off, and a connection when they are turned on via the web interface that you tested earlier.  Do this testing thoroughly since a short here could be dangerous.

Step 9: Cut arduino case down to size

The arduino case includes space for a battery that may make it too large to fit in the stoplight.  If you are using a case, you may need to cut this section off.

Cut the battery end off just up to pins and screw holes as shown in the picture.

This step made me sad.

Step 10: Wire stoplight to relay circuit

Picture of Wire stoplight to relay circuit
IMAG0120.jpg
IMAG0118.jpg
IMAG0121.jpg
You now should be ready to wire up the stoplight.  There are three "boxes" that need to be accounted for; the web server (arduino/ethernet shield), the control circuit and the 9 volt power supply.  With three lights you could theoretically place all three inside the lights, but I chose to keep the power supply external, thus insuring nothing could bump up against the power wiring by the middle light.  Experiment with these three to determine which ones will fit in the light.  If needed, all three can be external.

The 22 gauge wire (or the fat traces on the printed board) are the biggest potential risk of over-heating, so it's important to limit the amount of amperage they will ever be asked to carry.  To be extra safe, I added a 5 amp fuse to the circuit, which is several amps under the recommended max for 22 gauge wire.

In the case of the light I used, all the lamps were already wired to a block in the housing for the yellow lamp, so I just had to run wires from the control circuit to the corresponding posts on the block.  If it had not been there I would have just connected each wire via twist on connectors.

Each of the lamps swing up on hinges revealing space where wiring and other stuff can be tucked away.

DO NOT HAVE THE CORD PLUGGED IN DURING THESE STEPS!

Prepare the ac power cord:
  1. Create the power cord:  If you do not have a power cord with bare wires already broken out, cut the female end off of a PC power cable.  Strip the insulation off several inches of the bundle, and half an inch off of each of the three cables.
  2. Determine which wire is the ground:  Use a multimeter set in continuity mode to test which wire goes to the ground pin (the longer one) and make a note of it.
  3. Determine which slot of the outlet will be live:  The standard is that the thin slot is live and the wider one neutral, but testing it out myself gives me a greater peace of mind when wiring potentially lethal power.   After setting your multimeter to AC, put one lead in the ground hole and use the other to test the two slots in turn.  Whichever slot is live (should be the thin one, or your outlet is wired wrong) will send 120volts into ground when you connect them.  The other one should read zero or just a few volts.
  4. Determine which wire is live: Now that you are SURE which slot is live, put the multimeter back in continuity mode and use it to determine which wire corresponds with the the live blade on the plug.  Make a note of this wire as the "hot" one.  The final wire is "neutral".
Wire the stoplight per the diagram attached:
  1. Connect the "live" wire to the 5 amp fuse.  If you reverse it and use the neutral wire, the lamp will work but it will be a trap, waiting to shock or electrocute the first person to change a bulb. So don't do it.
  2. Run a wire from the other pole of the fuse to the "Power AC" screw on the terminal block on the control circuit.  This will be the one that connects to all four relays, the one separated from the others by one or more unused screws if you followed the printed guide.
  3. Run a wire from each of the terminal block screws to the corresponding lamp or outlet.  If you are wiring up the optional outlet, connect to the "live" terminal on the outlet*.
  4. Connect each of the remaining lamp wires (and the neutral wire of the optional outlet if used)* to the neutral wire of the power cord.  In the case of the light I used, all the neutral wires were already connected together, so I only had to connect one.
  5. Connect the ground wire to any ground wire provided by the light.
* See notes about the optional outlet

Test and power on:
  1. Test all your connections with the multimeter to make sure there are no shorts. With nothing plugged in, there should be NO continuity between the fuse and any of the lamp or outlet wires.
  2. Plug in power and ethernet to the arduino, but DO NOT PLUG IN THE LIGHT.  With the multimeter you should be able to get continuity between the fuse and the neutral wires of each lamp only when that lamp is turned on via the web page.  Similarly, you should get continuity between the blades of the plug when any of the lamps are on, but not when they are all off.
  3. Stand back and plug in the light.  You now should be able to turn each lamp on and off via the web page.

Congratulations, you now have a stoplight web server!

Step 11: Mount stoplight

If you haven't already, figure out which of the components can reasonably fit inside your light and decide which ones will be external.  In the case of this light, we decided to keep the 9 volt power supply external (up in the ceiling) and the other stuff inside the light.  This makes troubleshooting easier since all the custom components can be accessed simply by opening up the light and swinging the lamp out on a hinge.

To keep parts from rattling around in the light, you should secure them by whatever means make sense for your light.  I used a hot glue gun to glue the backs of the project boxes to the insides of the chassis.

If the light is just going to sit on your desk, you are pretty much done.

There are a number of options for mounting the light.  There are holes on the top and bottom where pipes can be attached and wires routed.  We had considered mounting the light on a pole, but decided instead to buy a wall mounting kit.  This kit consisted of two pipes with right angle fittings that mated to the light, and brackets on the other end to mount to the wall.

I wasn't present when a colleague mounted the light, but my understanding is that the steps were something like this:
  1. Attach pipes to light.
  2. Figure out where the light is going to hang, and where the brackets will subsequently touch the wall.
  3. Attach brackets to wall using heavy duty drywall anchors.
  4. Drill hole in drywall through the hole in the middle of the top bracket.
  5. Attach light to brackets.
  6. Fish power wires though top pipe and into wall.
  7. Feed ethernet cable through top pipe into light.
  8. Plug in power cords into power strip mounted in ceiling.

Step 12: Talking to the stoplight

The web page presented by the stoplight is really only for testing.  If you want to tie the stoplight to real world events you will need script web calls to change the light on whatever trigger is desired.

To do this, you need to formulate web calls to the extremely lightweight "API" the light responds to.  In other words, you have to have your script craft a url that looks like an http GET request.

This url looks like:

http://<your stoplights name or IP>:<port>/b?<argument>&<argument>

The arguments are each separated by an & and should be one or more of these:

  • a= The "secret" password.  Not encrypted in any way, this is only to prevent casual browsers from resetting your light.  If this is not right the light will not change, it will just return a web page showing how it would have changed it, had the password been correct.  The password should not be any of the other words or subsets of them.  i.e. "yell" would be bad because it's a substring of "yellow"
  • c= One of: "red","yellow","green" or "beacon" to turn on the corresponding lamp or the auxiliary outlet. 
  • "error=1" to start the yellow light light blinking
  • "error=2" to start the red light blinking (We use this when we really want to call attention to something)
  • "error" (without a =1 or =2) to flash all three lights twice as fast as they flash when first powered on.
So, if your script needed to turn on the red and green lights, and your light is called "stoplight.example.com" you would have it make a call to "http://stoplight.example.com/b?a=secret&c=red&c=green".

Except in reality the server is just searching for certain keys words and ignores all the other characters.  So that example could also be "http://stoplight.example.com/bsecretredgreen" and work just as well.

We use it in conjunction with a server monitoring package.  Every five minutes during the day a script looks at the aggregate results of the things we care most about, and decides what state to set the stoplight to.  After hours, a single call turns all the lights off to save power.

Step 13: Notes

Laser challenge

As stated in the intro, I would REALLY like my own laser cutter. In this particular project it probably wouldn't have been much use, although I would like to experiment with using a laser cutter with self-etched PCBs. There are, however tons of other projects I fantasize* about doing if I had one. Just a few:
  • Edge-lit Christmas cards.  Last year I made these cards and they were well received. With a laser cutter I would get a lot fancier with the window.  More importantly, I would like to experiment with etching the plastic itself with the cutter, allowing tremendously more complicated designs (and a less sore thumb) than I achieved with a push pin.
  • Personalized Christmas ornament cards.  Another card idea is be personalized balsa wood cards that would have components to punch out and assemble into ornaments.  About a decade ago I sent out Christmas cards that included an origami crane as an ornament.  A picture of it on a friend's tree showed up on facebook last year, so I know such cards are treasured and kept.
  • Personalized wooden air planes to give out to every child I know.
  • Any custom shim, brace, filler or decorative part I need cut for any small project.
  • Engrave any phone or other electronic device with important information and silly art.
  • Make parts for a CNC device.
  • Do any and many of the hundreds of projects on instructables and other sites that include "cut these pieces out with a laser cutter".
  • Make my own enclosures for my projects that are exactly the right size.
  • Make beautiful and useful things.
  • Make beautiful and useless things.
* often, when I probably should be sleeping

Bulb Brightness

The original choices offered by the stoplight vendor were 60 watt bulbs and 40 watt bulbs, with the latter being recommended for indoor use.  The people sitting near the light quickly discovered that even 40 watts was obnoxiously bright.  The reflectors are VERY efficient at directing the light outward.  We ended up replacing the bulbs with 20 watt appliance bulbs and the results are much nicer.  The light can still be seen well from anywhere in view, and the folks in the cubes under it no longer have to bring umbrellas for shade.

PCB vs protoboard

If you have the time, I strongly recommend having a PCB printed, with the earlier mentioned caveat about the fact that this layout is untested. The wiring to the protoboard is tedious. If you do get it printed, please let me know if there are any problems with the board layout in the zip file. (It has since been successfully printed by an instructables user.)

Optional Outlet

The original plan called for a fourth output to a wall outlet.  We had planned to use it to plug in a beacon or noise maker for "extra urgent, everyone drop everything, the world is going to end" type events.  In the end we did not want to mar the light by drilling holes in it, and decided that making the red light flash during such an event was sufficient.  The fourth output is there in our light and it can be triggered to make a "click" sound, but if you don't plan to have this feature you can just leave it out and save yourself the cost of a relay.

If you DO include an outlet as a fourth output, it is important to note that you should not plug in any device drawing more than 430 watts (3.9 amps).  This is because the total draw (including all three lamps on) must not exceed 5 amps or the fuse will pop and you will have to open the light to reset it.  DO NOT consider leaving out the fuse because the relays are not rated for more than 5 amps.  Drawing more would be a fire hazard.

Other lights

There are a couple of other similar projects I've found:
  • I used http://rockwellschrock.com/projects/traffic-light/ (which I found after I thought I had made up the idea) for some sanity checking.  This light requires a computer attached directly via USB to control it, but does have a more flexible control protocol. Someone unhappy with the options for controlling the light (which meet all our specific needs) might consider taking bits of his code and merging them with mine.  His design forgoes a complete arduino and just uses the atmega chip which makes it smaller and cheaper.  I used a full arduino because I needed to integrate with the Ethernet shield.
  • Apparently github has a light, used to denote build status. I discovered this page after I had finished the project.  This implementation uses a separate board for each relay, via three sparkfun relay boards.  This approach adds to the cost and possibly the size, but doesn't require any additional circuitry. Since each of the relays are separate, there is probably more flexibility about placement in the light, since the relays can be distributed anywhere there is room.  This project is also notable that instead of being notified by an external service of what state it should be in, it acts as a client and polls a web server to see what color it should be.  His comments about having to make the arduino reset itself every once in a while to combat a memory leak introduced by using DHCP makes me glad I chose to use a static IP address.


1-40 of 48Next »

Holy sh*t this is awesome!

Maybe i could build a smaller version one :)

nodoubtman1 year ago
where did you buy those lights?
thanks!
marC:)
mkanoap (author)  nodoubtman1 year ago
See step 1: "Materials" for some suggestions on where to get stoplights. These came from http://www.trafficlights.com/polysigs.htm
nickbart2 years ago
Hey, just wanted to add to the accolades and say this was a great tutorial. Also wanted to let you know that I ended up getting a PCB made for this and it worked great. I also wrote a PHP class to make sending the HTTP quests easier. I posted a little write up on my blog, giving you due credit of course, and included photos of the PCB and the finished circuit:

http://su.percilio.us/2012/05/arduino-stoplight-web-server/

Thanks for the great work!
mkanoap (author)  nickbart2 years ago
I'm so excited that you printed the board and more than that, it actually works and fits in the box! Logically it should have, but I've miss-measured things wrong often enough that I'm always amazed when something comes out right the first time.

Thank you for your kind words and for testing the gerber file for me. :) It's really cool to see the printed version of the board.

I'll update the article to indicate it's a valid board.

I noticed that you put in the 4th relay. Are you using it for anything?

Yeah, the PCB seems to work great. I did have little trouble when only two of the relays seemed to be sending power to the screw terminal, but I think that was down to my soldering. I resoldered a number of the joints and it seemed to be fine after that.

I did install the fourth relay, mostly because I thought I MIGHT use it and the relays came in a pack of eight, but we are not currently using it for anything. It does click whenever you send it a "beacon" command, but, for now, that's all it does.
ghostman!!2 years ago
Im not sure if its me doing something wrong, but when ever i try and use someone elses code from here, it never works !


stopduino.cpp:12:23: error: SdFatUtil.h: No such file or directory
stopduino.cpp: In function 'void setup()':
stopduino:97: error: 'FreeRam' was not declared in this scope
stopduino.cpp: In function 'void loop()':
stopduino:156: error: 'FreeRam' was not declared in this scope


Not sure :S
mkanoap (author)  ghostman!!2 years ago
You are missing the "sdfat" library, or specifically, the SdFatUtil.h file that comes with it. You can get the latest version from http://code.google.com/p/sdfatlib/downloads/list. I apologize for not putting it in the article, it snuck in because I was initially following the tutorial at http://www.ladyada.net/learn/arduino/ethfiles.html and was planning to have a prettier web page with the html stored on an SD card.

Since I ended up not doing that, I commented out the line that loads "sdfat.h". But the lines that print the free ram use a function that is in sdfatutil.h, and I forgot that it didn't come with the arduino.

I'll update the article to reflect this library later today.

In the mean time, you have two choices.
1) download and install sdfat from the link above.
2) comment out the line that loads sdfatutil.h AND all for lines that refer to "FreeRAM"

Let me know if this helps or if you need any further assistence.
mkanoap (author)  mkanoap2 years ago
I have updated the sketch to a) remove the dependency on that library and b) make it compatible with the 1.0 version of the arduino IDE as well as earlier ones.

http://stopduino.googlecode.com/svn/trunk/stopduino/stopduino.pde

Let me know if this fixes everything for you.

Errorrrrrr Errooorrrrrr


stopduino.pde:-1: error: cannot declare parameter 'client' to be of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: because the following virtual functions are pure within 'Client':
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:12: note: virtual size_t Client::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:13: note: virtual size_t Client::write(const uint8_t*, size_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:14: note: virtual int Client::available()
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:15: note: virtual int Client::read()
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:17: note: virtual int Client::peek()
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:18: note: virtual void Client::flush()
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:10: note: virtual int Client::connect(IPAddress, uint16_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:11: note: virtual int Client::connect(const char*, uint16_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:16: note: virtual int Client::read(uint8_t*, size_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:19: note: virtual void Client::stop()
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:20: note: virtual uint8_t Client::connected()
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:21: note: virtual Client::operator bool()
stopduino.pde:-1: error: cannot declare parameter 'client' to be of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: since type 'Client' has pure virtual functions
stopduino.pde:-1: error: no matching function for call to 'Server::Server(int)'

As of Arduino 1.0, the Server class in the Ethernet library has been renamed to EthernetServer.

/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Server.h:4: note: candidates are: Server::Server()
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Server.h:4: note: Server::Server(const Server&)
stopduino.pde:-1: error: cannot declare variable 'server' to be of abstract type 'Server'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Server.h:4: note: because the following virtual functions are pure within 'Server':
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:48: note: virtual size_t Print::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Server.h:6: note: virtual void Server::begin()
stopduino.pde:-1: error: cannot declare parameter 'client' to be of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: since type 'Client' has pure virtual functions
stopduino.cpp: In function 'void doform(Client)':
stopduino.pde:-1: error: cannot allocate an object of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: since type 'Client' has pure virtual functions
stopduino.cpp: At global scope:
stopduino.pde:-1: error: cannot declare parameter 'client' to be of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: since type 'Client' has pure virtual functions
stopduino.cpp: In function 'void loop()':
stopduino.pde:-1: error: 'class Server' has no member named 'available'
stopduino.pde:-1: error: cannot declare variable 'client' to be of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: since type 'Client' has pure virtual functions
stopduino.pde:-1: error: cannot allocate an object of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: since type 'Client' has pure virtual functions
stopduino.pde:-1: error: cannot allocate an object of abstract type 'Client'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Client.h:7: note: since type 'Client' has pure virtual functions
mkanoap (author)  ghostman!!2 years ago
These errors are going to be trickier. It seems that between the time I wrote this and now, the areduino environment moved to version 1.0 and at that time they broke a bunch of stuff by renaming functions and doing other things that make it not backwardly compatible.

I can't really update the actual stoplight because it's doing it's job in production, but I have another ethernet shield I can experiment with. I'll try to make a version that works with 1.0 this coming week, since other people are likely to run into this in the future.

In the mean time, you could probably just install an earlier version of the arduino IDE and (with the library mentioned on the comment above) have it compile. If you are using an UNO, I believe you need to have installed 1.0 first because it provides a driver for it, but you can have multiple versions of the IDE on the same machine.
mkanoap (author)  mkanoap2 years ago
I forgot the mention, the offending changes are to the ethernet library, which comes with the current version and older versions of the IDE. They changed "Server" to "EthernetServer". :(
I hadn't done any soldering in a while, so as a way to ease into this project one of the first things I did was solder the headers to the ribbon cable - easy to fix and re-do if I screwed up (plenty of ribbon cable and extra headers).

When I came back to this step to attach the 6-pin connector after doing the rest of the project I realized I could just make out the location of the red marked cable in this picture of the connector and the ribbon cable - at this orientation the red is on the top. It was easy enough to confirm with my digital multimeter as well but I didn't want to crimp it the wrong way and (I think) ruin the connector.
mkanoap (author)  buckmeisterq3 years ago
Since you could plug the connector in either way, it doesn't really matter which way the red ribbon cable goes, as long as it's the one you end up plugging it in so it ends up at pin 1.

It would be important if the pins were set in a socket matching the header, which would be a much more elegant way of doing it than the 6 bare pins I recommended.

I've added a note in the picture to show which one was the red one for those with less sharp eyes than you, and added a bit more info to the following step. Thanks again for the feedback!
I used 20ga wire (or 22ga? it was solid wire rated for 300watts) for the 120v portion and nothing seems to be heating up or catching on fire yet. I didn't see a mention of a size for the 120v portion, but it seems like we're dealing with such a small amperage max (limited by the 5A fuse) that it should be OK.
mkanoap (author)  buckmeisterq3 years ago
According to http://www.powerstream.com/Wire_Size.htm, 22 gauge wire is appropriate for up to 7 amps, so that's why I specified that size.

20 is good for 11, so you are twice as good. :)
I finally had time to finish my stoplight, thanks again mkanoap for this great instructable.

I ended up purchasing the LED model stoplight from LightsToGo LLC - it really didn't have room inside the lights to put much of anything (except the 5amp fuse) so I have my boxes outside the stoplight.

Here's my mouser list of parts in case anyone else is interested, I started without any parts, just tools:

1 - 2x3 socket for ribbon cable: 649-71600-106LF
5 ft (plenty extra) - 9 pin ribbon cable: 523-191-2801-109
1 - 9 volt power supply: 552-PSC-12R-090-R
4- NPN Transistor: 863-2N3904RLRAG
1 - Arduino kit (the breadboard and jumpers similar to what's in the LED test setup): 782-A000032
4 - Relays: 817-LZ-9HE
1 - 36 pin block of headers: 649-68001-436HLF
4 - Diodes (rectifiers): 625-1N4004-E3/54

I couldn't find the right screw terminal blocks on mouser (the ones I bought didn't have legs to solder through the PCB). I found them at Radio Shack 2761388 PCB Term 2P 5MM. I also bought 22 gauge wire there, as I said I really didn't have any materials when I started.

A friend gave me some 1/2 watt 1K ohm resistors, they weren't in the list but they're needed.

This is some other stuff I got that is pretty obvious but I'll list it anyway:

1 - Arduino Ethernet shield: 782-A000056
1 - Arduino board (it is the Uno): 782-A000046
1- Arduino enclosure: 782-A000009
3 - Red/Yellow LEDs: 606-4301F11/17
3 - Red/Green diffused LEDs: 607-4301F1/5
6 - 1/2 watt 180 ohm resistors: 660-MF1/12LCT52R181G

I'm a newbie and I wanted to follow the instructions as closely as possible so as not to mess myself up by diverging too much from the original project. It was tedious wiring everything on the protoboard myself. If we like this stoplight as a way to get notifications on the build I'm probably going to build some more, and I'll have the PCB printed for me at that point - maybe even dabble with POE, or try making it wireless somehow.
mkanoap (author)  buckmeisterq3 years ago
It's great to hear that you built it, and I'm happy to hear my instructions were helpful.
I was going to say "what do you mean the resistors aren't listed?" But then I checked and saw that yup, they are on the schematic, but not on the parts list!

Sorry about that! All I can say is that they WERE on the project list that mouser deleted. :)

I'll update the article to reflect the missing resistors, and see if I can't dig up the screw terminal block part number.
Hi, im a small website server owner and i have built your project. Could you please possibly post an example script?
nervermind i worked it our, but for people who want to control it without a browser and dont know how heres is a basic html line you can add to control it

<.script GET src ="http://stoplight:port/bsecretredgreen"/>

is an example of turning red and green on

except get rid of the dot before script(its just so instructables doesnt treat it as a html line)
LesB3 years ago
So...I notice the traffic light in the picture is RED! So while you were taking pictures for this instructable for our benefit, your servers were flaming out.
mkanoap (author)  LesB3 years ago
Ha! That's the kind of sacrifice I'm willing to make for instructables. :)

But seriously, two important points.
1) It's a good policy to alert BEFORE a server is in an unusable state. Red might mean "the disk is 90% full" or "cpu load is twice as high as normal" as well as "server not responding."

2) If you don't yet have your monitoring system hooked up, this light just displays whatever you last set it to with the web gui.

sing1ejack3 years ago
Thanks for putting up such a great pricing and sourcing list, by the way. It's always discouraging to look at a great instructable and not be able to guess whether it's pie in the sky or actually doable. It's less intimidating when I have a link for unfamiliar parts and can identify the pricey parts (and brainstorm ways to bring down their cost).

Actually, I would love for instructables to give authors a structured way to list the materials. Perhaps a search-as-you-type field that would then provide resource links and average prices. I know they're resourceful enough to do make this happen...
probably a way is to skip the standalone option and link it with a computer
Maybe home servers would benefit from this because they can attach it to the server itself (which could save the user from a trip to where it is placed, which is usually hidden)
mkanoap (author)  beehard443 years ago
See the notes for a similar project which works that way, directly connected to a computer.

Some of the articles that appear automajically to the right of this one also may be pertinent.

If you don't need the Ethernet ability, you can save $45 right off the bat.
mkanoap (author)  sing1ejack3 years ago
Thanks. I have shared those frustrations in the past and that's why I did it. Nice to know it's appreciated.

It was an even better list before mouser deleted the project so people can't just put it in their shopping cart. :)
beehard443 years ago
suggestion, make it dim the lights and activate red beacons if there is a really serious error
mkanoap (author)  beehard443 years ago
A beacon was in the original design and there is even a relay still there for it, but we found that flashing the red light was sufficiently eye catching for the "drop everything" events.

I like the idea of dimming the lights for added drama.
This is a really cool project and I'd like to give it a try myself (I'm a bit new to this arduino stuff but I've always had a knack for soldering).

The mouser project links take me to an "arduino" project that only has 4 items listed, and when I try searching for the "NPN Transistors 2N3904" there are dozens to choose from.

Also I'd be interested in finding out more about which arduino ethernet board would be the drop-in replacement? (I found 4 in a search on mouser).

And one more request, sorry, any recommendations on where to get the PCB printed? If this first one works well I might make a few more :-)
mkanoap (author)  buckmeisterq3 years ago
Rats. It seems that mouser didn't like me sending all that traffic to their shopping cart and summarily deleted my project. Highly irritating and a bit short sighted I think.

I'll try to figure out the part numbers from PO and update the article tomorrow, maybe with digikey parts. :) Honestly though, I just picked the cheapest. 863-2N3904RLRAG is a whole 3 cents cheaper and should do fine for those transistors.

The ethernet arduinos are hot off the presses, so I'm just speculating here. I'm thinking A000050 would be the closest replacement. Note that this model requires a special cable/adapter, not just a regular USB cable. It looks like A000060 is the same thing with the the new version of that adapter stuck on.

The other two you found are versions of those two with POE (power over ethernet). I would have LOVED to have built this with POE and eliminated the separate 9 volt adapter, but it was not yet available. Most switches don't provide POE, so don't bother with those unless you know you can use it.

I have had good luck with http://batchpcb.com for getting single boards printed at $2.50 per square inch plus $10 setup per board. But you have to wait a few weeks sometimes for a board to fill up. This board is about 7.5 square inches so it would be around $29.

Similar services I want to try but have not yet are:
http://dorkbotpdx.org/wiki/pcb_order ($5 per square inch, no setup and you get three copies! But you also have to wait for a panel to fill up with other people's orders. That would be $37.50, but only $12.50 each if you needed all three

http://iteadstudio.com/store/index.php?cPath=19_20 ($24.90 up to 10cm X 10cm (which would probably fit this board), and you get 10 copies!) You could throw out 9 and still be cheaper, or use all 10 at $2.49 each!
LesB mkanoap3 years ago
Newark Electronics is another supplier option. They have the widest selection of any supplier I know of. And I think they have a parts list service.
akahn23 years ago
There's a great company in upstate NY just south of Albany that sells traffic signals and parts: http://www.twingreenonline.com/signals.htm , they have LED traffic lights and it's a lot cheaper than the site mentioned in the Instructable for either LED or incandescent signals.

mkanoap (author)  akahn23 years ago
Thanks, I'll make a note of it. Looking at their page reminds me that you can also get red/green lights, leaving out the amber. That's a good option for anyone who doesn't need the yellow to cut down on the cost.
hammer98763 years ago
Great idea. So much more high tech than what we had years ago. Each server was represented by a small toy animal that were kept on top of a cubical wall. When (not if) the server went down, someone would tip the toy nose-down. Everyone had to stand up to see if the Giraffe server was dead in the water, but the system worked.

I like your instructable better.
mkanoap (author)  hammer98763 years ago
Now I'm envisioning some systems with solenoids to automatically tip the toys down and back. That would be cool.
juanman803 years ago
Hi, nice job!
for us, europeans that visit this place, what would we need to make this project with 220 V bulbs?
mkanoap (author)  juanman803 years ago
I considered talking about that but in the end didn't because I simply don't know, and didn't want to speak from ignorance about stuff that could get people electrocuted. I have an irrational fear of 220 volt power. :)

Also, I know nothing about European wiring codes.

I will however say this:
1) Those relays are rated for 2.5 amps at 240 volts each, so they should not melt or anything.
2) The calculations I made for the "don't plug more than this in" rely on the equation "current (amps) = watts/volts". So I looked at the bulbs (40 watts originally), added all three together and got 120 watts. It's easy to divide 120W/120V, so I knew that the lights would be drawing 1 amp max. That told me a 5 amp fuse would be plenty, and leave room for current draw from the optional socket. So the key number to consider would the be the wattage of the bulbs. If (for example) you had 60 watt bulbs, the calculation would be (3 X 60) / 220 = .82 amps. Still plenty enough to kill you if it crosses your heart, but even less amps than the 120 volt version.

So I'll tentatively say that the only modifications to the instructions would be for the plug, which I didn't have a picture of anyway.

If anyone sees anything blatantly wrong with the above assumptions, please comment before something tragic happens.
sdtacoma3 years ago
Great idea. I wish my work would adopt something like this.
jneveln3 years ago
Thanks for this write up. I've had a traffic light for years since I got one at a Dept. of Transportation surplus auction a long time ago. Not as long ago I got an Arduino and an EFX-TEK RC-4 relay board (http://www.efx-tek.com/topics/rc-4.html) to control it with, but was getting stuck on the little fiddly bits needed to connect it all up and where to get them. I went with the pre-made relay board so I didn't have to do as much on the 120 V side of things. This will help a lot.

I plan to set mine up a bit differently, adding some other sensors like a distance sensor so I can put it in the garage and have it tell me when to stop, or an audio or stereo connector so it will blink in time to music. Plus just do normal traffic light-style blinking.
mkanoap (author)  jneveln3 years ago
I love that idea about having the light tell you when when to stop the car, it sounds like your light will end up being more fun than mine. :)

That board looks pretty nice and cheaper than getting a single copy of my (hypothetical) board printed. It's too bad the cost of the Solid State Relays drive it back up again, but it's still an attractive alternative.
1-40 of 48Next »