I picked up three giant traffic lights at a surplus store, because really, how I could I pass them up at $12 each? I thought it would be a great display item / game / piece of artwork for the Alpenglow Industries shop, and the perfect project to teach my team beginning Arduino skills!
DETAILSThis project started with an impulse buy of 3 giant traffic lights at a surplus store. The possibilities are really endless, and they're a great excuse to teach some Arduino skills. See the project logs for all the details!
Summary:
- Controlling the lights with big arcade buttons seemed the obvious choice
- The lights are 120VAC, so they need relays to control power on/off (lit/unlit)
- I sketched up a crappy schematic, to explain how to hook up the relays, arcade buttons, Arduino, and a power distribution rail
- Robyn W did all the work of hooking everything up
- I made a bad assumption about the power distribution terminal block rails, and the first time we plugged it in, there was a big spark and we tripped the breaker on the power strip. Yay for using a power strip with a breaker for the first power-on. Boooo for not having beeped out the terminal rail or mains power before plugging it in. I know better! But Robyn W got to observe my mistake and learn a valuable lesson!
- She then took the lights home and made a sweet enclosure box for them
- She's now altering the code to change button behavior
- The end goal is to make them into a Simon Says game, so the next steps will be to incrementally add functionality to the software, and eventually have a sweet shop game and art piece!
To start off we drew up a schematic then gathered the various components we would need including: Arduino Leonardo clone, 3 large lighted buttons (red, yellow, green), 3 relay modules (to control the 120 VAC going to the lights), a solderless breadboard, 2 terminal blocks, and misc. Wires and connectors. After all the parts and the basic design was completed assembly could begin!
We used an Arduino to control the traffic lights via relay modules because we wanted the flexibility to change the interaction of the buttons with the traffic lights and for the simplicity of programming. In total 9 pins were used, 3 for the switch inputs, 3 for the switch lights and 3 for the relay modules. Relay modules were used because the traffic lights operate off of 120 VAC. We also made a small traffic light simulator using a perfboard and 3 LEDs this way we wouldn't need to hook up to the giant traffic lights every time we wanted to test the code.
We already had a Leonardo microcontroller and breadboard mounted on a base plate. We then took the 3 relay modules and the 2 terminal blocks and mounted those onto a larger 3D printed scrap base plate. Following the schematic previously drawn up we wired together all of the components. To connect the lights to the relay modules I attached 3 two pin Molex connectors to the output, 1 for each color. Then attached the mating connectors to the traffic lights. We 3D printed custom housing for the large lighted buttons.
TRAFFIC LIGHT HOUSINGDesigning and building a housing for the traffic lights was the next task. The face of the housing was constructed from ½ in. birch plywood. We chose the birch plywood due to the strength of the wood since large circles were to be cut from it to hold the lights, leaving very little material left for support. The circles were cut using a jigsaw circle cutting jig. The sides were constructed from ½ in MDF which was used due to its lower cost. 1 in. grid pegboard was used for the back of the housing because, well, that's what we had laying around in our garage. Using Some leftover scraps of wood we made small wedges to secure the lights in place on the inside of the housing. For a nicer looking finish we made some decorative trim for the face using scrap 2x6 redwood lumber. The lights were wired to come through the back of the housing and secured with a strain relief. We then attached the mating Molex connectors. As a last detail, I made 3 bezels from ¼ in. black irrigation tubing to go around each light that covered the gap between the light and the plywood face. After finishing the housing I needed to make a 10ft. Wire extension cables from the housing to the relay modules.
If we wanted to hang the lights on the wall we were going to need some wire extensions. I took black and white 18g cable (10ft of each color) and twisted them together using a drill. Next I used wire strippers to take off the insulation on the ends and attached the female 2 pin Molex connectors and then did the same thing with the male connectors on the other ends. Finally I put red, green, and yellow electrical tape on the ends to easily identify which wire went to which light.
Starting off with writing the code for the traffic lights we had to identify the inputs and outputs. We needed 3 inputs (one for each button) and 6 outputs (3 for the relay modules, 3 for the button lights). In the first version of the code a button press would toggle the corresponding traffic light on or off (yellow to yellow, red to red, green to green). With the 2nd version when a button is pressed, the button light is on while the button is depressed (does not toggle)
Simon says Game ModeIt was cool to have traffic lights that we could turn on and off but what else could we do with these lights? Well, why not make a giant Simon says game!
Once the lights are plugged into power all traffic lights and button lights blink once to show it's on and working. After that press any button to start game mode.
The first steps to making the game were creating a predetermined sequence of light blinks and to have the Arduino recognize if we pressed the correct button in correlation with the traffic light color.
Then we used a randomseed algorithm to make the light blinks be random.
every 3 light blinks and the the time in between blinks speeds up!
Get 10 in a row correct and the green traffic light blinks 3 times indicating GAME WON!
Take too long to press a button or press the wrong button and 3 red light blinks from the traffic light indicate GAME LOST!
Comments