3. Replacing a Microcontroller to Change the Timing of a Traffic Light

(article continued from previous page)

If you jumped to this page of the article via a search engine, then the title may raise false hopes. I’m discussing how to modify a toy stop light, not a real one. Although this technique is applicable to miniature traffic lights for railroad and slot-car tracks, it won’t work for the big ones on the street corners. I’m afraid that you’re going to have to find another way to shave 2 minutes off of your commute.

Selecting and Trimming a Prototype Perf Board

If this project is going to be duplicated on a larger scale -- such as for more than a couple of traffic lights, then the printed circuit board should be reproduced using a PCB production house. For a single board of a small circuit, we can use a generic perf board.

Three-hole solder-pad perf board

Three-hole solder-pad perf board.

There is a wide variety of readily-available, off-the-shelf perforated prototyping boards available from most electronic mail-order companies (Mouser Electronics, DigiKey, Jameco, etc). Unlike a custom PCB, the traces and holes on a perf board are generic to support any project.

The perf boards with metal pads around single holes are the most common. I prefer the perf boards with metal pads connected in groups of three or more, such as pictured above. The groups make it easy to solder a component (switch, socket, transistor lead) into one hole, with room for one or more connecting wires in the other holes. This arrangement is similar to the layouts on solderless breadboards.

Perforated prototyping board with a DIP socket and a miniature switch.

Perforated prototyping board with a DIP socket and a miniature switch.

There is plenty of room in the electrical box of the toy stop light lamp that I purchased at Target. However, I need to make sure the added circuit board doesn’t get between the LEDs and the color filters, or else it will block some of the light. Therefore, it is preferrable to cut the perf board down to the smallest reasonable size.

To determine the optimal board size, temporarily arrange components where you can best take advantage of the groups of holes. Leave room to drill several larger-diameter holes for screws to secure the board.

Since it is unlikely you'll find a perf board with the exact dimensions of your project, you’re going to want to cut it down. This means you can save money by purchasing a larger board and using pieces for numerous projects. Before removing the components, indicate the corners (or draw an outline) of where you want to cut the board.

Some people score the board multiple times with an Xacto knife or razor blade before snapping it. But, I’ve never had much luck or patience for that process. Instead, I use a Dremel with a rotary cut-off wheel or an industrial shear to cut the board to the desired size.

Microcontroller override wiring layout.

Microcontroller override wiring layout.

The new board is cut and the components are soldered in place. As you can see, overriding the existing functionality of the traffic light requires a lot of wiring.

A diode, capacitor, and expansion connector are added.

A diode, capacitor, and expansion connector are added.

The above photograph was taken after additional changes were made to the new board.

Threaded spacers hold the new circuit board.

Threaded spacers hold the new circuit board.

The old board screws onto molded round spacers that hold it in place and keep it flat by lifting up the irregularly soldered side.

To mount the new board, you could drill holes through the thin plastic lid and use nuts on the outside, but that would look ugly.

Instead, you can obtain some pre-tapped spacers (like DigiKey #1902AK for $0.50 each) or make your own. In either case, screw the spacers against the new board, put a few drops of super glue on the bottom of each spacer, and press the board onto the desired location on the lid. After the super glue dries, you can add some epoxy around the edges of the spacers for added strength.

New Microcontroller Performance

For this particular project, I selected an Atmel AVR ATtiny45 microcontroller with 4K of program space. The traffic-light algorithm fits into less than 2K, but I find that it is more cost effective to buy 10 or more of the larger capacity chips that can be used for other projects as well.

The new default mode shows a steady green light for 10 seconds, a steady yellow light for 3 seconds, and then a steady red light for 5 seconds. It would be just as easy to program in different amounts of time.

Pressing the on/off pushbutton now switches to other modes, such as solid red, solid yellow, and solid green.

The final mode powers everything off, just as the original chip did. The ATtiny45 disables all the LEDs, sets the pushbutton pin to an interrupt, turns off all of the built-in hardware modules (timers, etc), and then enters power-down sleep. Pressing the pushbutton causes an interrupt and the chip restores everything back to the way it was.

Despite a lot of effort, I could only get the chip to power down to 20 µa (0.02 mA), which is hundreds of times more power usage than the original chip. This could be because I have a stock of early ATtiny chip versions, or it could be an error in my code. It doesn’t matter because the AAA batteries can last over 6 years with that amount of drain. I most likely will run the stoplight from AC power anyway.

The final feature I added was an automatic power down mode after 5 hours. This is an arbitrary amount to prevent unintentional continued operation. After powering off, pressing the pushbutton restores the last mode.

The expansion connector is currently unused. It could be used to turn the traffic light into a debate timer (by hooking the spare pin to a potentiometer to set the speech limit). Alternatively, it could be used to interconnect many traffic lights into a serial communication network.

Given the salvageable parts and potential uses, you might want to keep an eye out for a sale on these already inexpensive desktop traffic lights. They sure make it easy to modify them.