loading
Picture of Fully-functional Duplo traffic light
My kids love playing with Duplo vehicles.  And my eldest recently became fascinated by traffic lights.  So I figured they might get a kick out of having a traffic light that lit up, and could change from red to green, and back, with the touch of a button.

My design goals for this project were:
1. It must be kid-proof - including an inquisitive toddler.
2. It should be properly compatible with Duplo sets.
3. It must be an authentic traffic light sequence - in the UK, that's Red, Red+Amber, Green, Amber, Red.
4. The battery should last a long time between changes.
5. It must be cheap!

In total, not counting the cost of the Lego parts (which were all scavenged from sets lying around the house) this traffic light cost me less than £5 UKP.  Here's a video of it in action:


This is my first Instructable, so bear with me!
 
Remove these adsRemove these ads by Signing Up

Step 1: Ingredients

Picture of Ingredients
DSC05742.JPG
DSC05737.JPG
DSC05736.JPG
DSC05730.JPG
Here are the bits you'll need to make this traffic light.  Obviously you can vary according to personal taste or what you have lying around - all of these things were scavenged from odd lego sets and electronic parts that I had already.

2x standard Lego 2x4 black bricks (part code 3001)
1x Lego Technic black ribbed hose (part code 78).  I used this for the 'pole', as it's flexible so much harder for kids to break!
1x Lego Traffic Cone (I couldn't find a part number, but it's in this cheap set: 5679)
1x Lego Duplo 2x2x1 black square brick (part code 3437)
1x 5mm Red LED
1x 5mm Yellow LED
1x 5mm Green LED
(I think that using LEDs with coloured, rather than clear, plastic gives the best effect)
1x small tactile pushbutton with a round button (like this)
1x CR2032 coin cell
1x CR2032 battery holder (like this)
1x ATTiny45 or ATTiny85 microcontroller
2x very small machine screws + bolts (I think I used M3 x 25mm)
A blob of BluTac or similar putty-like substance
A small length of hookup wire - preferably solid core rather than stranded.  Having multiple colours, especially red, yellow and green, helps.

As for tools, you'll need:

Soldering iron and solder
Wire strippers and cutters
Drill or Dremel with a selection of small bits, including 5mm.
Hacksaw
Superglue (be careful at all times not to glue your skin - that stuff sets FAST and strong).
Small screwdriver
Small pliers
Craft knife
Hot glue gun
Some way of programming the microcontroller - you can use an Arduino (using these instructions), or a dedicated programming tool such as an USBtinyISP.
A breadboard or other electronic prototyping environment, for testing the program.

Step 2: Programming the microcontroller

Picture of Programming the microcontroller
The microcontroller is the mini computer that provides the brains for the traffic lights.  We need to make sure that we've got it working before we start assembling anything.

First of all, download the code - attached to this article.  Flash it to your ATTiny using your chosen programming environment.  If your environment allows you, you should also set the fuses in the ATTiny to use the 1MHz internal clock, and no brownout detection (lfuse=0x62,hfuse=0xDF,efuse=0xFF).  This isn't critical, but will improve your battery life.

Now plug your ATTiny into a breadboard, connect up the LEDs and switch as in the circuit diagram.  When connecting the LEDs, connect the flat side of the LED to GND, and the other side to the pin on the ATTiny.  Now connect up the battery holder, and insert the coin cell.  You should see the red LED light up.  Press and release the switch, and it should go to red+yellow, then green.  Press and release the switch again, and it should go to yellow, then red.  If you're unhappy with the timing, then you can tweak the TRANSITION_TIMEOUT constant.

Once you're happy that it works as you'd like, unplug the power and we'll move on to building it into the Lego blocks.

Step 3: Check that everything fits

Picture of Check that everything fits
DSC05728a.JPG
There's not much space to play with in this project, so it's important to make sure that you know how you're going to fit everything in.

First of all, check that your LEDs will fit the 3 round tubes on the bottom of one of the 2x4 bricks.  It'll probably be a little too tight at this stage, but almost fit.  That's fine.

Check that your switch and battery holder will fit completely inside the traffic cone - the switch goes in first, and the battery holder will probably need to go in diagonally.

Finally, check that your hose (or other choice of 'pole') fits snugly in the top of the traffic cone.  It might not push all the way in yet - that's OK, so long as it fits the opening.

Step 4: Mounting the microcontroller

Picture of Mounting the microcontroller
To keep things small, we're going to solder the microcontroller directly to the battery holder.  Start by turning the battery holder over, so that its pins are in the air.  Identify the VCC and GND pins on the microcontroller - these will connect to the + and - pins on the battery holder, respectively.  Turn the microcontroller so its pins are pointing up in the air, and bend those two pins outwards towards the battery pins.  You should be able to bend the battery pins over, so that both pins on the microcontroller touch both pins on the battery holder.  Make a note of its position.

At this point, add a dab of superglue to the top of the microcontroller, and glue it carefully and quickly into place on the battery holder.  Now solder the two connections.

We also want to connect the reset pin to VCC.  It's directly opposite that pin, so solder a small wire straight across.

Identify the red, yellow and green LED pins, and solder wires to those.  You should allow about 6 inches of wire.  It'll be a lot easier later if you colour-code those wires.

Identify the switch pin, and solder a 3 inch wire to that.  Solder the same length of wire to the GND pin (which is already connected to the battery holder).  Finally, solder a second, 6 inch wire to the GND pin.

At this point, if you're paranoid, you can try temporarily connecting up the rest of the circuit again, to check that it still works.  If you're happy, snip off the unused pin on the ATTiny.

Step 5: Mounting the LEDs

Picture of Mounting the LEDs
DSC05728a.JPG
DSC05745.JPG
DSC05748.JPG
First we want to mount the pole onto the traffic cone base.  My traffic cone had a ring of small protrusions inside the stud on top, which were just smaller than the diameter of the ribbed hose.  The opening of that stud was exactly the right width to accept the hose.  I found that to insert the hose fully, I had to make a shave a little bit off 4 sides of the end of the hose, to align with the protrusions in the opening.  I could then insert the hose, and twist it to kind of lock it in place.  You could also make a slit in the end, to give it enough flexibility to get past the protrusions.

Once you're happy that the hose fits, add a dab of superglue and permanently fix it in place.  You should find that it's pretty much impossible to pull it out - an important bit of kiddyproofing.

Next step is to mount the LEDs in the two small black 2x4 bricks.  You'll have realised by now that we're going to mount the LEDs in the 3 small tubes in the bottom of the brick - pushed in from the top of the brick.  First step is to drill the holes in the top of one of the bricks.  If there's any difference between your two bricks, then choose the one that's got the nicest looking bottom.

Grab your drill / dremel, and a 5mm bit for drilling metal.  Drilling slowly and carefully, drill through the top of the brick, in the space exactly between 4 adjacent pips.  You'll probably find that your drill bit is slightly larger than the internal diameter of the tube, in which case just drill far enough into the tube to allow an LED to fit snugly inside, with its base flush with the top of the brick.  Repeat for the other two tubes.

With your other 2x4 brick, first hack out most of the length of the underside tubes - they'll just get in the way of the back of the LEDs.  Check that your two bricks fit snugly together, one on top of the other, with an LED in place.

You also need to make a hole for the pole.  I used a drill with a bit just the same size as the external diameter of the ribbed hose piece, just touching the edge of the brick, as seen in the picture.  I then also hacked out a small groove in the plastic on the top of the LED brick, to make sure that the two bricks still fitted snugly together with the hose in place.

Now stick the LEDs properly into their holes (in the right order - red, yellow, green!).  Line up their flat sides so that they're all along one side of the brick.  Bend the legs on the flat side so that they lie flush to the brick, and touch each other along the length of the brick.  Solder those legs together, and trim off any excess wire.  Now bend the other legs flush to the brick, and trim off all but a very short length of wire, making sure that they're not touching each other or any other wires.

Pass the red, yellow, green and long GND wire through the hole in the middle of the pole piece, and push the battery holder into the base of the cone.  Ensure that you'll have enough wire to connect through the pole and to the LEDs, allow a small amount (1-2 inches) of slack, then trim those wires to the right length.  Solder the GND wire onto the interconnected flat-side LED legs, and the other wires onto the other legs of the  appropriate LEDs.

At this point, let's be paranoid and check that everything still works if we stick the battery in the holder. 

If it's all good, then check that the two 2x4 bricks still fit together snugly with the pole in place, then add a dab of superglue to the pole/brick joint, and check that it holds securely.  Now add superglue to the joint between the two bricks, and join them together permanently.  Wipe off any excess glue from around the join quickly, before it sets.

Step 6: Mounting the switch

Picture of Mounting the switch
DSC05737.JPG
The next task is to mount the switch to the base.  I chose to mount it quite high, on the slope of the cone - you could put it anywhere that you can make it fit (making sure that the battery holder etc. can also still fit inside the base).

Most of these small pushbuttons come with four pins.  By now, you now which two pins you're going to use (since you've tested the circuit) - usually it's two on the same side of the body.  Trim off any unused pins.

Measure the size of the part of the button that you actually press.  On mine, it was a circle roughly 5mm in diameter.  You want this hole to be as snug a fit as possible (remember the childproofing - you don't want drool getting inside!), so choose a drill bit that's as close as possible in size.  Using an appropriate drill, drill a hole into the cone where you want the button.  Check that it fits from the outside first, and make any necessary adjustments.

Solder the remaining two wires from the microcontroller onto the switch.  Stuff it inside the base, and check that the button can still be pressed (though you might need to stick a finger inside the base to hold it still at this stage.  Now that all the electrical connections are made, you can test the circuit again to be sure that it's still working, and that the switch does the right thing.  At this point, once you've verified that everything is still working, it's a good idea to stick a copious amount of hot glue over the pins of the ATTiny.  That helps to avoid the stresses of being stuffed into the base from dislodging any of the connections.

All fine?  Good, now you need to make sure that the switch is now secured in position.  I used a large blob of Blu Tack, stuffing it into the top of the base, behind and around the switch, bit by bit, until the switch was securely wedged into position.  Now stuff the battery holder (making sure you've inserted the battery) and microcontroller assembly into the base, maybe adjusting the Blu Tack wadding as necessary.  You need to end up with everything packed in as tightly as possible, at a minimum with nothing protruding beyond the level of the bottom of the base - you should be able to stand it on the table, and it should make full contact.  I found that I could just achieve this - but that I wasn't able to attach the cone properly on top of a Duplo brick - the battery holder poked down onto the studs of the brick and stopped them from fully engaging with the cone.

At this point, if this isn't to give to kids, and you're not worried about being able to stand the traffic light properly onto Duplo, then you could stop and consider the project finished.  But I needed to be able to seal the base from prying fingers, whilst still being able to change the battery occasionally, and be able to attach it to Duplo.  Read on for how I achieved that...

Step 7: Mount the base

Picture of Mount the base
DSC05730.JPG
DSC05761.JPG
DSC05763.JPG
DSC05752.JPG
The first task in sealing the base is to make sure that the cone and the 2x2 brick used for the very bottom of the light can fit together properly.

What I found was that I'd wedged the battery holder in pretty well, but that one corner of it was still interfering with one of the studs on top of the 2x2 brick that I wanted to use for the base.  So, I just used a craft knife to carefully slice that stud off from the 2x2 brick.  With it gone, the cone and brick fitted together perfectly.  Do whatever you need to do.

To attach the 2x2 and the cone together semi-permanently, we're going to use the machine screws.  Check that the screws, and the nuts that they connect with, are small enough to fit inside the Lego bricks.  If you've got the right size, then the screw head will fit perfectly in the gap between the slope of the cone, and the corner of the base of the cone.  Measure the diameter of the threaded part of the screw, and find a drill bit to match.  Carefully drill holes in opposite corners of the lip of the cone, where the screws will go through it.

Check you're happy with how the screws sit, then connect the 2x2 to the cone.  To make sure that the holes will line up properly, pass your drill bit through the hole in the cone, then drill again vertically until you've made a hole in the 2x2.  Repeat for the other hole.  Check that the screws still fit well.

If you're using the same size screws as me, you'll probably find that if you try to fit the 2x2 onto another piece of Duplo now, then the screws are just a bit too long, and interfere with the studs on the other piece.  If so, use a hacksaw, or a Dremel cutting wheel, to cut the screws a little shorter.  Be careful not to overdo it though - you only need to cut off a small amount.

You should now be able to fit the nuts onto the screws.  This is quite fiddly, and a pair of tweezers may help to hold the nut in position for the first couple of turns of the screw.  Tighten the screws (but not too tight - I managed to crack a brick the first time I did this).  Although tempting to avoid small parts coming loose, I don't advise using threadlock to secure the nuts - many threadlock compounds are toxic, and your kids are sure to put this traffic light in their mouths at some point.

Step 8: All done!

Picture of All done!
At this point, you should have a finished, working traffic light.  Congratulations!

Before handing it over to your kids, check that there are no sharp edges, loose pieces or surplus glue.  If necessary, file down any sharp edges on the screw heads.

My calculations predict a battery life of 2-3 months under average use.  So far the battery in mine has lasted well over a month of heavy use, and is still going strong.

Thanks for reading this far, and I hope you enjoy your new toy!
simon.w.nordberg made it!4 months ago

Hey! I made a modified version for my girlfriends nephew!

Check it out: http://www.instructables.com/id/ATtiny85-Traffic-l...

2015-03-17 02.58.35.jpg
Can u make me one of these?
TomekPL1 year ago
Hi,

why are you not using resistors to limit the current flowing through LED?

I was searching for ideas how to build traffic lights and that's how I came to your site.

BR,
Tomek
FanjitaUK (author)  TomekPL1 year ago

Hi Tomek,

The coin cell isn't capable of putting out enough current to damage the LED, so a resistor just isn't necessary. You can happily wire an LED directly to a coin cell and it will be fine - do a search for "LED throwies" to see another example that makes use of this fact.

Hi,

thanks for your reply. So the red LED (with let's say forward voltage @ 1.8V) also doesn't require a current limiting resistor because the battery (3 Volts) is so low current source- correct?

BR,
Tomek

FanjitaUK (author)  TomekPL1 year ago

Correct. A typical small LED generally has a max current rating of about 10-15mA. The typical maximum discharge current of a CR2032 is about 4mA - so there's lots of margin.

I've found a great article that explores this topic http://www.evilmadscientist.com/2009/some-thoughts...
it turns out, it's good to use current limiting resistor if you want to have long battery life. Note the current they measured using red LED.

Duplo brings back memories....
FanjitaUK (author) 3 years ago
Thanks for the praise.

I knew I wanted to make it as soon as I noticed the perfect pattern of 3 tubes on the bottom of the small bricks, and it was a fun exercise bringing it all together.

Most important of all, the kids love it!
techxpert3 years ago
try a 555 timer not as simple but no programming required
FanjitaUK (author)  techxpert3 years ago
Yeah, I considered a 555, but I happened to have a pile of ATTinies lying around, they're almost as cheap, and their great advantage is the minimal parts count. There's so little space inside the Lego that space was critical.

The ATTiny is programmed to go into deep sleep when the button hasn't been pressed for a while, to preserve battery life. I think that would also be pretty hard to achieve with a 555-based approach.
mikeasaurus3 years ago
Fun idea, I like it!
Very nice!