In this project we make electronic dice.
In this article you can learn how to make an electronic die (die is the singular of dice), using an ATmega328 with Arduino bootloader and a few inexpensive components. The reason for doing this is to introduce another object that you can build, learn from and be proud of. It is a fairly simple procedure, and at the end you will have something that is useful for a long time to come. Again this article will be a design-narrative, so please read it in full before making a die yourself.
First of all, here is a photo of my finished product.
Naturally the cosmetic design is up to you, I have used this box, LEDs and switches as they were already in my stock of parts. The die is quite a simple design – with a twist. Inside the unit is a mercury switch. This consists of a small glass tube with two wires at one end and a small amount of mercury. When the mercury rolls over the wires, they are shorted out. Just like a push button when it is pushed, for example:
We will make use of this switch to start the die “rolling” – to simulate the use of a non-electronic, under-engineered wooden die. For safety, I will be using a mercury switch that is enclosed with plastic:
Over the last few years several people have contacted me saying “don’t use mercury switches”. Fair enough, if you don’t want to either, use element-14 part number 540614.
First of all, the circuit is assembled on a breadboard using our Eleven Arduino-compatible board. There is no need to build the complete independent circuit yet, as we just want to test the aspects of the sketch, and try various LEDs out. I have some bright blue ones which match with the blue housing:
There is a function in the sketch (below) called
which is used to display the numbers 1 to 6. The following video is a demonstration of this:
The sketch is quite simple – you can download it from here. Once the behaviour of the die met my expectation, I used my ZIF-socket programming board to upload the sketch into a nice fresh ATmega328 with bootloader. One could also add a piezo buzzer for sound effects, as described in sketch. This will end up being a birthday present for a young niece, so I have omitted the sound effects.
Next, time to rebuild the circuit on the breadboard – using the bootrom and not our Eleven. Here is the schematic:
and the resulting layout:
And it works! Things are starting to come together now. As usual I was curious about the current draw, as this helps me determine how long the battery will last. On standby it draws between 10 and 20 milliamps, and between 30 and 40 milliamps when displaying numbers.
By now you probably would like to see it work, so here is the prototype demonstration:
Now it is your turn… from a hardware perspective, we will need the following:
- IC1 – ATmega328 with Arduino bootloader programmed with the sketch
- IC2 – LM78L05 voltage regulator – note that with the front facing you, pins are 1-output, 2-GND, 3-input
- D1-D7 – LEDs of your choosing
- R1, R9: 10 kilo ohm resistors
- R2-R8: 560 ohm resistors
- X1 – 16 MHz resonator – centre pin to ground, outside pins to IC1 pins 9 and 10
- small piece of protoboard
- SW1 – on/off button
- SW2 – mercury tilt switch
- 9V PP3 battery and snap
- optional – 28-pin IC socket
- a nice case, but not too large
- some thin heatshrink
- some sponge or insulating foam which has a width and length slightly larger than the protoboard
The ideal housing would be one that fits in the palm of your hand. However, such miniaturisation levels are quite difficult in the home workshop. The biggest problem (literally) was the power supply. The only battery with the voltage and a decent amp-hour rating was the 9V PP3. Alkaline models are usually good for 500 to 625 mAh, and should power the die for about ten hours of continuous use. Furthermore, whilst running the prototype on the breadboard, it would function down to 6 volts, however the LEDs were a little dim – but still perfectly usable. However I managed to squeeze it all in – sans the IC socket.
So if you are like me, and soldering the IC in directly – make sure you are happy with your sketch!
Anyhow, time to start the hardware work of assembly. Using veroboard/protoboard is easy if you plan things out first.
Remember – to fail to plan is to plan to fail
So in this case, I like to get some graph paper and draw out the tracks with a highlighter, such as:
My diagram shows the tracks as they would be on the rear of the veroboard. With this, using a pencil one can mark out component placement, links, and where to cut tracks if necessary. Those long lines are great for +5V and ground. Etcetera. When you have laid out the parts, go and have a break. Return and check your work, then fire up your iron and go!
Once completed you then have an easy to follow plan to solder along with. Here is the above example after I finished soldering:
After the soldering was completed, and the board checked for any shorts or poor-quality joints – it was time to have a clean-up and clear the mess away. Now it was time to stuff the whole lot into the housing… but it would be prudent to test the circuit beforehand. So I soldered in the tilt switch, and the battery snap, connected the battery – and it worked. Notice in the image below the placement of the centre LED – I have used some heatshrink over the legs to totally insulate them, and have it at the centre of the board:
Now to focus on the enclosure. In order to keep the costs down I used a box (and almost everything else) from my existing stock. It turned out to be a little small, but with some creative squeezing everything would fit. The PCB and battery are separated by a thin layer of anti-static foam, to prevent the possibility of the sharp edges of the PCB underside scratching the label of the battery and causing a short.
The final messy task was to drill the holes for the LEDs and the power switch. The switch was easy enough, just knock a small hole in then use a tapered reamer to get the exact size:
Then to drill the holes in the lid for the LEDs to poke through. Easily done, just be sure to mark where you want the holes to be before drilling. Furthermore, you need to get the LEDs as far through the holes as possible:
Then the final step before sealing the lot up is to get the power wires soldered to the switch and the battery snap:
When you are putting everything in the box, make sure the tilt switch is tilted so that when the die is at rest, the tilt switch is laying in the off position. Otherwise the die will just merrily repeat forever until you turn it off.
And of course, an action video:
Once again I hope that this demonstration has shown how easy it is for anyone with some spare time and the knowledge from my Arduino tutorials can create something from scratch.
In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.