Thursday, December 17, 2009

Duplo Traffic Lights

We've been playing with LEGO and DUPLO quite a lot at home recently (Lin's been doing some great work on expanding our LEGO possibilities - see these posts over on filthwizardry: "Lego and hole punching cards", "Festive card punching with more LEGO", "LEGO and DUPLO" and "LEGO car and DUPLO truck cardboard printables").

I thought it'd be really nice to be able to add some traffic lights (like these ones I made a while back) to the creative fun. Lin suggested I house some in a DUPLO block, so I set to work trying to figure out how to do it.


Ingredients: 3 LEDs (red, yellow, green), 3 resistors (I used 330 ohm), ATtiny13, 8 pin DIP socket, perf board, magnet wire (thin), switch, stranded wire (black and red), coin cell battery, DUPLO blocks (the 8 knobble variety, 1 standard and 2 thin).

Tools: soldering iron, dremel, hot glue gun, various dremel attachments and drill bits (depending on your LEDs and switch).

The three holes/cylinders on the underside of a standard DUPLO block are perfect for traffic light mimicry. I ended up using 3 blocks, one large and two thin. The large block houses the electronics and the switch, one thin piece has 3 holes drilled in it for the LEDs and the last piece is used on the back as a battery cover.

Here's a couple of pictures showing the carved out bricks. You have to leave some of the 'tubing' in the large brick in order for the other brick to still connect normally. I used a dremel to cut off the 4 middle bobbles from the thinner piece - leaving a hollow center, between the two pieces, for the electronics.

I haven't taken a picture of the remaining thin block, I hollowed that out in the same manner as the larger block, to make room for the coin cell battery. Again leaving enough of the innards so it'd still fit tightly on the back of the main block.

I drilled 3 holes in the front piece (the thin black one above) directly in the center of the three tubes; the holes need to be just the right size for the LEDs to fit snuggly (I messed this up with my first prototype). I also drilled a small hole in the center of the big block for the power wires to feed through later on. This way you can have all the electronics hidden in the main block and have the battery accessible on the back.

The main board is just a small bit of perf-board with the 8-pin DIP socket soldered on. I'm using the same code as last time, so the LEDs and resistors are attached to pins 5, 6 and 7 (PB0, PB1 and PB2 respectively). I used magnet wire to attach the LEDs as it's flexible and takes up very little room. I tried just soldering the LEDs directly onto the perf-board but that made it difficult to get a good fit later on. If you give this a go, remember to sand the insulation off the ends of the magnet wire before soldering.

Add a switch:

Then place it all inside the main block (feeding the power wires out of the hole in the back).

Then glue the LEDs into the holes of the front piece and close it all up. I'm probably going to have to glue it shut in the future to keep out fiddling fingers.

I didn't have a coin cell holder, so I scavenged some metal tabs from the innards of a happy meal toy and soldered these onto the ends of the power leads. Then I taped them tightly onto the coin-cell. Clip on the battery cover (3rd block) and it's all done. This would all be a bit cleaner if there was a coin cell holder attached to the back in some way (I'll give that a go next time).

Here's the lights in operation (with my first attempt on the right which has directly soldered LEDs and an ugly switch):


The kids really do seem to like them! The original lights have had to be repaired a few times from er... 'overly keen' play. Well, that and Ffion ripping them apart.

Next ideas are to make them easier to include with normal duplo play by attaching blocks to the top and bottom (may require some cutting and gluing). Another good addition would be to have lights on both sides of the block to control traffic in both directions (so when one side is green the other is red). If only I had more black duplo...

Sunday, November 22, 2009

64-bit Windows 7 and the AVR ISP USB programmer

Just a very quick note about this.

I upgraded my laptop to 64-bit Windows 7 a week or so ago and have just gotten round to setting it up for AVR programming. I thought for a while that I'd never get my USB programmer to work (AVRStudio couldn't auto detect my AVR ISP even after installing/reinstalling). After a little bit of searching I found this thread on I followed the directions, allowed windows to discover the correct drivers at the end of the process and, badabing-badaboom, everything now works fine (other than the fact that I installed a 32 bit Eclipse that isn't happy...).

Tuesday, November 3, 2009

LED Tester Mark II

Ok, so the last one I made had a serious flaw... it'd burn out any LED that couldn't take 3V... Oops! I recently bought a new soldering iron (variable temp, xytronics from and wanted to play with it, so I thought it was time to replace the LED burner with an LED tester.

Basic ingredients: wire, some resistors, an 8 pin DIP socket, a pushbutton and some perfboard. I treated myself to an automatic wire stripper the other day ($8 from Fry's), it's great! I've been using it quite a lot. No need for it in this project really, but I like to show off my toys.
Here's the basic wiring and soldering for the resistors and socket (this is what I messed up in the first iteration):

At midnight I ended up with the following "finished" product (I should have learned by now not to start late at night...):

The problem was that I'd completely wired the push button wrong. In the above wiring, the power lines are connected to the positive and negative rails on the DIP socket, which meant the LEDs lit up as soon as they came in contact with the DIP. On pushing the switch the LEDs would turn off because the positive and negative leads from the battery holder were shorted... bah!

A few days later, I came back and repaired it (button connects and disconnects +ve terminal, -ve terminal is wired directly):

A view from the top.

Single LED test. You can see the multi-LED test picture at the top of this post.

The soldering iron is much better than the Weller I'd bought (it was a bottom of the line weller min you). It heats up fast and the tip is noticeably better quality. The power cord, however, is very thick and reduced the maneuverability of the iron.

Sunday, November 1, 2009

Flashing Bat Eyes


Very simple project. You just need a 555 timer a couple of resistors, a capacitor, a couple of LEDs and a talented wife to provide a bat ;) I think she'll be adding a post on making the Halloween bats so I'll link to it once it's up.

I used the following online calculator to work out the values for R1, R2 and C1 for the standard astable 555 set up. I ended up with: R1 = 3K Ohm, R2 = 570 Ohm and C1 = 100uF (mainly because that was the combination of components that I had lying around and that gave an acceptable output wave). I didn't bother adding a switch to this one, I'm not sure why as it'd be very easy... here's the fully wired up project:

Did you notice the 9V battery clip onto an 2xAA holder? Weird eh? Useful though. I think I picked up the battery case at radioshack. You'll also have noticed that I decided to try a free-form (no perf-board) approach. It was a bit fiddly, but worked out ok. I still haven't found a combination of 3rd hand/clamp/foot/nose that works for me for these fiddly soldering projects...

Here's a couple of close-ups of the soldered 555 itself:

Most of the time I had the 555 held with a crocodile clip (on the 3rd hand). Unfortunately, I bought a really cheap 3rd hand from a market and the crocodile clips are not stable so everything kept moving around whilst I was trying to work on it... bah. At points I ended up jamming the chip into a corner of the 3rd hand base whilst pushing at it with the soldering iron. Not very elegant or skilled... any advice is greatly welcomed!

All that's left was to poke out some holes for the bats eyes and to mangle it all into the available space. I made the holes big enough for the dome of the LEDs to fit through but small enough to prevent the rest of the LED housing from pushing through.

And here it is outside our house (flashing on the opened door frame), waiting to welcome the trick-or-treaters :)

Saturday, October 31, 2009

ATmega programming board

Recently I've been playing with some projects that required more IO pins than the ATtiny has to offer. I bought a few ATmega8's from ebay and have about 3 of them installed in various breadboards at the moment. All the wiring was getting very frustrating, so I decided to make another programming board to reduce the clutter and to make my life a bit easier.

The process was almost identical to that for the ATtiny header board. There are only two real differences: 1) this is a board designed to fit the ATmega8 AVR chip so it has a 28 pin DIP socket and 2) I used a bad purchase (wide 28 pin dip socket) as the female headers for wiring up to the breadboard projects.

The wiring is practically the same as the ATtiny board. If you've ever wired an ATmega to a breadboard (or to anything else) you'll easily be able to work this out. There's more room to maneuver with the larger 28 pin board as well, which was nice.

Here's the 'bad purchase':
I mistakenly bought a few of these wide 28 pin sockets (as part of another allelectronics purchase). These have been sitting in a drawer all but forgotten. I noticed them whilst retrieving the narrow 28-pin socket for this board and figured these would be useful as female header rows if I just chopped them in half. It turns out they fit really well & look pretty good too.

Saturday, September 12, 2009

LED Cube

I've wanted to create one of these for ages. There are a ton of instructables out there for how to make various versions of these from 2x2x2 cubes to 8x8x8 monsters. I wanted to make something reasonable for a first attempt, but fun enough to look at. I figured a 3x3x3 is a good start.

There's also been quite a buzz the last few months around using LEDs as both light emitters and light detectors. I wondered if the LED cube could be made more interesting by also making it detect changes in ambient light. Perhaps that's a little too ambitious for the first iteration, but I can at least plan for this feature as a software (rather than a hardware) update later on. It turns out that there's nothing extra needed, hardware wise, for light detection with LEDs (check out this post on spritemods, which is a great example: minimalism; Jeroen also posts the source code, which I'm going to "borrow" from rather liberally when I get round to trying the light detection part). Don't expect any of the light detection fangling in this post - I'm only going to describe making and testing a 3x3x3 LED cube. I mention the light detection stuff because it's cool and I wanted to pressure myself into getting round to doing it by publicly announcing my intent :)

Anyway, first things first, lets get a working cube soldered and tested.

For the initial test set up I used the following: 9 LEDs (I chose all blue), an ATmega8, 12 breadboard jumper cables, 3 alligator clips (for the cathodes), a couple of breadboards and my regular USB AVR programer and associated paraphernalia.

To make the soldering process easier I created a jig from a plastic box in the recycling bin. I made a 3x3x3 grid of holes, spaced 25mm apart (just a little less than the length of the LED cathode leads). I marked out the holes with a sharpie and then blasphemed by melting the holes with my soldering iron...

I pushed in the LEDs into each hole with the anodes (long leads) facing outwards - we're going to be soldering all the anodes in a column together later on and it seemed sensible to have them on the outside of the cube, where they'll be easier to get at. Then I bent the cathodes down 90o so that they touched the cathode of one of their neighbours.

Here's the jig with the first set of LEDs in place, ready to solder:

The middle LED only makes one connection, which makes it a weak point in the layer. I was tempted to add a couple of extra connections from it to make it more stable, but I figured that, after soldering the layers together it should be stable enough. I just added a bit more solder to that particular connection in order to strengthen it.

After soldering all the leads together, you gently pull each LED out of their hole. You can then pull the whole assembly away and marvel at your soldering skill ;). Then it's time to start over again...

Here's the full set of 3 layers all soldered nicely (still separate though):

The final step in creating the cube is to solder the layers together. There must be a better way than what I tried, but here it is: I placed one layer back in the jig, cut off a few small strips of sellotape, positioned the next layer on top so that the anodes from the lower layer overlapped enough to solder to the next layer and then secured the two layers together with the sellotape (synonym:scotch tape). I soldered the corners first to give some amount of stability to the emerging structure.

Whilst soldering the third layer I worked out that the best method was to position the lower anode lead on the outside of the upper LED, then bend about 2mm of the lower lead 90o towards the upper lead and then solder them together. The bottome left LED column in the second picture below shows what I mean:

And here's the completed cube:

I'd not actually programmed an ATmega8 before, but it was fairly straight forward to modify my ATtiny setup. I just had to work out which pins to attach the programmer to (by looking at the atmega8 datasheet). The trickiest part ended up being getting the cube securely placed into the breadboards (I wish I'd given into a previous whim to buy one of the bigger boards now). The picture below shows my test current set-up with the cube installed.

I tried to come up with the simplest test I could imagine whilst ensuring I was addressing each LED correctly. So my first test just powered up each individual LED in order, one layer at a time.

Here's a video of it in action:


I've included the code below for those interested. Just bear in mind that this was specific to the way I wired up the cube. It's a shame 9 columns have to be used for this as it means using multiple registers for the LEDs, which means we have to specify which columns are on which registers. Maybe someone out there can show me a better way to do it?

* led_cube.c
* Created on: September 6th, 2009
* Author: Paul
#include <avr/io.h>
#include <avr/delay.h>

//define the cathode pins
//I just happened to connect them to these pins
#define LAYER1 PD1
#define LAYER2 PD0
#define LAYER3 PD2

//define which pin each column (anode) is connected to
uint8_t kColumnConfig[] = {PD3, PB7, PB3, PD4, PD6, PB2, PB6, PD7, PB1};
//store the layers in an array as well
uint8_t kLayerConfig[] = {LAYER1, LAYER2, LAYER3};

//this function switches a column on or off
//we have to know which port the column is a part of
//hence the switch statment:
// PORTD pins are at indices 0,3,4,7 in the kColumnConfig array
// PORTB pins are at indices 1,2,5,6,8 in the kColumnConfig array
void setColumn(uint8_t pVal, uint8_t pCol)
//portD pins
case 0:
case 3:
case 4:
case 7:
PORTD |= (1 << kColumnConfig[pCol]);
PORTD &= ~(1 << kColumnConfig[pCol]);
case 1:
case 2:
case 5:
case 6:
case 8:
// portB pins
PORTB |= (1 << kColumnConfig[pCol]);
PORTB &= ~(1 << kColumnConfig[pCol]);

int main(void)
uint8_t i = 0;
uint8_t j = 0;

DDRB = 0xFF; // all set to output
DDRD = 0xFF; // all set to output
//swich off all layers by applying voltage to the cathode pins thereby preventing current flow
PORTD |= (1 << LAYER1) | (1 << LAYER2) | (1 << LAYER3);
//loop through each layer
for(i = 0; i < 3; i++)
//set the output value for this cathode layer to '0'
//this allows current to flow in this layer
PORTD &= ~(1 << kLayerConfig[i]);
for(j = 0;j < 9; j++)
//turn on the LED in column j
setColumn(1, j);
//trun off the LED in column j
setColumn(0, j);
//set the output value for this cathode layer to '1'
//this prevents current flow for this layer
PORTD |= (1 << kLayerConfig[i]);
return 1;

Monday, September 7, 2009

PVC Pipe Marshmallow gun

This post is a bit of a diversion from the normal electronic fangling, but it's such an easy and fun project that I wanted to share.

I was flicking through a recent purchase, "The best of instructables (volume 1)" , and I landed on page 232 - "The marshmallow shooter". It's labour day (sorry: "labor day") which means that we were having a lazy Monday at home so we decided to take a trip to Lowes to pick up the necessary bits to make a few shooters.

That's all you need (and some marshmallows). The pipe is 1/2" schedule 40 PVC, it was 89c for about 5 feet of the stuff (enough for 3 shooters). I also picked up a few different fittings: three way junctions, four way junctions, elbows (with different angles), caps and some couplings (to use as mouthpieces). I also picked up a pipe cutter; I've experienced the "joy" of using a hacksaw for cutting pipes (those ones get a brief mention on filthwizardry: music tree) . This time I decided on an easier option.

First off we cut up the pipe into various lengths, short pipe for the handles and longer ones for the main body. We washed all the bits thoroughly.

Here's all the parts that went into our first three guns:

Next up I showed the girls how all the parts fit together. I helped to tighten the parts, but that was all the intervention necessary. It's all very easy and simple. I think I'm going to get a load more of the piping and fittings and just let the kids play with it free-style sometime soon.

After getting all the parts together, they decided their creations needed to be decorated before we could use them :) We had a strange coincidence here: before heading to Lowes we popped into the local Savers (they were having a labor day sale) and what did we find in the book section? A book on making marshmallow guns (here's the Amazon link)! Very weird! Being from Savers, it didn't come with any of the piping, but it did have most of the stickers left (not anymore though!).

Time to try out the beautified guns on Lin.

They had a great time blasting (and eating) the mini marshmallows. The great thing about using marshmallows is that, strangely, there was no mess to clean up afterwards...