Sunday, February 28, 2010

The Amazing Dr Boardman's Colour Conundrum

"Roll up! Roll up! Try your hand at The Amazing Dr Boardman's Colour Conundrum!"

This is a little game I've been planning on making for quite some time. I finally got round to learning the necessary microcontroller details to pull it together. The basic idea is that that there are two, full colour 'bulbs'. One bulb lights up with a random color and the player tries to match this color by adjusting the RGB values of the second bulb (the bulbs are actually RGB LEDs with ping-pong ball diffusers). When the colors are similar enough then the player 'wins'.

This was quite hard to do for the younger kids, so I added a speaker to the mix & set it so that the sound frequency increased the closer the player got to the correct colour. It's still pretty hard, even with the speaker on.

I added a difficulty switch so that the daring/cocky can turn the speaker off.

Here's a little video of it in action. My 5 year old daughter kindly agreed to walk us through it.

How it was put together


  • 3 potentiometers (20K ohm - but the absolute value isn't very important)
  • 3 knobs for the potentiometers
  • 8 ohm speaker
  • wooden box (I found this one at Savers)
  • perf board
  • 2 baby food jars
  • 2 ping-pong balls
  • 28 pin DIP socket
  • ATmega8
  • 2 RGB LEDs (common anode)
  • 2 toggle switches (for power and speaker on/off)
  • hook-up wire

First off drill holes in the ping pong balls, the box and in the baby food lids. Obviously, the size of the holes will depend on what you want to put through them so you'll have to work this out yourselves). Here's the layout I used:

There are 3 holes in a row for the potentiometers, two holes for the LEDs, one hole in the middle for the difficulty switch and one on the side for the power switch.

Next up is to solder leads to the pots. I used speaker hookup cable for the +ve and GND connections and then soldered 3 different coloured wires to the center terminals (I would have used blue instead of black, but I don't have any blue wire). These are going to control the red, green and blue levels of the 'player' RGB LED.

I sanded the LED lenses to make them diffused (I could have just bought diffused lenses... doh!) and then soldered the leads in place. I used some speaker cable again here too to keep things simple (and some heat shrink tubing to prevent shorts).

Then solder the DIP socket onto the perf board. Add the potentiometer leds and the power supply. All the wires were cut to be a little generous in length - I wasn't sure how everything was going to fit so I figured I'd play it safe and allow for wiggle room in the box.

I used one of the IC perfboards because I figured having the central Vcc and GND rails would make life easier as well as the already connected pads around each pin of the uC.

Attach the LEDs to the board:

Then add the speaker and difficulty switch (this just connects/disconnects the speaker from GND rather than being directly controlled by the microcontroller) and test the set-up for shorts, cold solder joints etc.

The LEDs are poked through the holes in the box without the ping-pong balls on (no surprise there). I had them on in the above photos to see how well they worked.

Place everything into the case and hot glue it all securely - I glued the switches and the LEDs in place.

I positioned the uC within easy reach so that I can tweak the software and update easily. Next time I think I'll just add programming headers to the board.

If you're very lucky then you're either artistically gifted or you have a talented partner in crime who can make your project look a hell of a lot better. Lin (my lovely lady and the hostess of had the fabulous idea of creating a Coney Island theme for this game. I take no credit for how good it looks, that was all down to Lin. I think I was going to put it in some old Tea box and leave it at that. Thanks, hon! She was also responsible for the game name. I'm far too British to call myself amazing. Oh, and the American spelling of colour she claims was for symmetry purposes.

I drilled a few holes in the back to increase the apparent volume of the speaker. Also, it took me a while to work out how to keep the lid/base on the box (there were no fasteners built in, the lid was meant to be kept on by gravity). I'd almost given up and was going to attack it with nails when I realised I could simply drill some holes in a couple of washers and screw them into the base... I'm stupidly proud of that little idea. Ah, the little things...


The code is available here on

The output from each potentiometer is read via ADC. These values are used as the 'player' RGB values and are compared with the 'game' RGB values. I started off using the euclidean distance of the RGB vectors as the difference metric, but - with kid friendly values - it meant that you could sometimes match red to green (and green to blue etc.). I ended up requiring each colour be within a defined distance for a successful match.

When a match is detected we turn off interrupts, flash the LEDs and modulate the speaker sound. Then switch interrupts back on and assign a new colour to the system RGB LED.

It uses double buffered software PWM for the LEDs and standard PWM for the speaker.

The only other trick is that the random seed is stored in EEPROM and incremented each time the uC is booted up. The incremented seed is fed to srand and from there we just use the rand() function. This way the game sequence is different each time (well, different for 256 games in a row anyway).
#include <avr/eeprom.h>
 * Use a variable stored in EEPROM to ensure the random color
 * sequence changes from one game to the next.
void initRand()
    uint8_t vSeed = eeprom_read_word(0); // load last stored seed
    srand(++vSeed); // increment and use value as seed
    eeprom_write_word(0, vSeed); //store the new seed for next time


Honeyspy said...

This is the coolest thing I've ever seen. :D

Rebecca said...


I wonder if I could get my hubby interested in electronics? I bet I could with the help of your blog and the beggings of our three children....

thank you!

Catatonic said...

Very nice project, well laid out, simple, and some fine craftsmanship in the artistic parts. Also adorable kids mate best choice for someone to explain how it works.

Kami said...

That is SO cool!

Shan said...

Wow, wow, wow! As always, I am totally blown away by the creativity and ingenuity of your family!

Claire T. said...

This is mad crazy cool! Forget the kids. I want one :-D

Mattie said...

Top Project. might need to make a couple for our collective Nieces and Nephews.
Why didn't you add current limiting resistors for the LEDs? I would have thought if say All blue came up 5 volt at 100% modulation would not be a good thing.

PaulBo said...

Mattie: It's only running on 2xAAs so the max voltage is 3v. I had intended on adding a max_level constant to the code so that none of the LEDs were at a 100% duty cycle. Current limiting resistors would have been the simplest solution though.

LeeSayao said...

Your project is awesome and I'd love to recreate it however when I click the link to the code, I get: "SVN hosting has been permanently disabled." Can you help?

PaulBo said...

The code for most of the posts here were hosted on - which is now defunct. I've moved over to github and am updating the links. The links on this page should work now.