7 December 2009 (updated 2 June 2012)
Copyright 2009 - 2012, Dan Newman
Distributed under the TAPR Open Hardware License, tapr.org/OHL
![]() |
|||
| 0.0 | Introduction | ||
| 1.0 | Getting started | ||
| 2.0 | Arduino | ||
| 3.0 | Large design | ||
| 3.1 | Components | ||
| 3.2 | Assembly notes | ||
| 4.0 | Medium design | ||
| 4.1 | Enclosures | ||
| 4.2 | Components | ||
| 4.3 | Assembly notes | ||
| 5.0 | Small design | ||
| 5.1 | Enclosures | ||
| 5.2 | Components | ||
| 5.3 | Assembly_notes | ||
| 6.0 | Operation | ||
| 7.0 | Compiling the sources | ||
| 8.0 | Ordering a PCB | ||
Using seven independentally controlled LEDs, this project implements animated digital dice using your choice of an Arduino, ATtiny24/44/84 or ATtiny2313/4313. By modifying the source code, additional animations may be added and additional AVRs supported. In addition to source code also provided are schematics, a breadboard layout, PCB layouts, Gerber files, and printable 3D models for two enclosures.
This project demonstrates using the following AVR or Arduino features
The necessary hardware is straightforward, requiring
C language source code for AVR-GCC is provided which has been tested on an Arduino Duemilanove (ATmega328p), an ATtiny24, and an ATtiny2313. The same source code file works for all three processors and can be used as an Arduino sketch.
Note that this document is not a tutorial on Arduino programming: plenty of those exist already. See, e.g., Adafruit's collection of Arduino tutorials. Nor is this document a tutorial on building and downloading firmware to an AVR. For an excellent tutorial on that subject, please see Evil Mad Scientist Laboratories' tutorial Blink an LED with an AVR. Finally, only terse assembly notes are provided: the reader is expected to be familiar with assembling simple electronic projects from a schematic.
The digital dice are presented in four different designs,
The Arduino design is the easiest to build and a good starting point. While each of these four designs is presented individually, they are all the same basic circuit. The first three designs use simple, everyday components. The fourth design uses some less common components such as a gull winged, surface mount push button and through hole SIP resistor networks. Those particular component choices allow fitting the circuit within a small key fob enclosure such as the commercial Serpac CA4,2 or the supplied 3D enclosure model which you can print yourself with a 3D printer.
The Arduino design is quite straightforward and, with components in hand, should take about ten to fifteen minutes to assemble. The finished assembly is shown below while a more clear breadboard diagram is presented following the bill-of-materials.
In addition to a breadboard and wires, you will also need the following items to assemble the circuit,
Quantity |
Component |
Usage |
|---|---|---|
7 |
LEDs |
Die "pips" (spots). Most any non-exotic, two lead LEDs will work (e.g., red 5 mm LEDs). |
7 |
1.2k 1/8W 10% resistors |
Current limiting resistors to control the amount of current flowing through each LED. The lower the resistance value, the brighter the LED will glow. Using higher wattage and/or finer tolerances is, of course, okay. |
1 |
10k 1/8W 10% resistor |
This is a pull-up resistor used with the push button switch. Any value in the neighborhood of 10k is fine; e.g., 12k or 15k is okay as well. Higher wattages and/or finer tolerances are acceptable. |
1 |
Tactile switch |
Pressing this switch causes the die to be rolled. Rolling continues until it is released. Select a momentary "on" push button switch which fits your breadboard. E.g., a 12 mm tactile switch such as Sparkfun's COM-09190. |
Assemble the components as shown below. Note that the orientation of the LEDs is important. In the illustrations below, the shorter lead of each LED -- the cathode -- is the one shown bent and extended to the ground "rails" of the breadboard. The longer leads -- the anodes -- face the centerline of the breadboard in the diagram.

As per the source code, the Arduino port assigments are shown below,
Digital Pin # |
Component |
Usage |
![]() |
|
|---|---|---|---|---|
0 |
LED 1 |
Die pip 1 |
||
1 |
LED 2 |
Die pip 2 |
||
2 (INT0) |
Switch |
Rolls the die when pressed |
||
3 |
LED 3 |
Die pip 3 |
||
4 |
LED 4 |
Die pip 4 |
||
5 |
LED 5 |
Die pip 5 |
||
6 |
LED 6 |
Die pip 6 |
||
7 |
LED 7 |
Die pip 7 |
After wiring the breadboard and double checking it, launch the Arduino application and open the dice.pde sketch file from the distribution (src/firmware/dice.pde).
Note that the file dice.pde and dice.c are identical: one is just named with the .pde extension so that double clicking on it automatically opens it with the Arduino application.
Build the sketch and download it to your Arduino. Once it has been loaded, one-by-one each of the LEDs will light up and stay lit. Proceed to Section 6, Operation for directions on testing and using your new digital die.
The large PCB design is a good first soldering project for new hobbyists. It's also the first PCB my daughters, then ages 8 and 10, designed. (My name is on the copyright since they may not be old enough to own a copyright in some countries.) While they designed the board as a two sided board, with careful use of wire jumpers or strategic resistor placement, it can be realized as a single sided board suitable for home fabrication. Should you wish to order a PCB, see Section 8, Ordering a PCB.
The simple schematic for the big PCB is shown below alongside the PCB layout; click on either image to enlarge.
![]() |
![]() |
To assemble the circuit, you will need a circuit board and the following components, two of which are optional:
Quantity |
Component |
Usage / Description |
|---|---|---|
1 |
ATtiny2313 or 4313 |
The AVR microcontroller in a DIP package. The ATtiny4313 is available from Evil Mad Science as well as very nifty programming kits for out-of-circuit programming. Well worth considering if you plan to work with AVRs. |
7 |
3 mm LEDs |
Die "pips" (spots). Most any non-exotic, two wire LEDs with 2.5 mm lead spacing will work (e.g., red 3 mm LEDs). Consider whether or not you want LEDs with clear (as in water clear) lenses versus with tinted lenses. A die with red tinted lenses will look different than a die with water clear lenses when the LEDs are not illuminated. |
7 |
1.2k 1/8W 10% resistors |
Current limiting resistors to control the amount of current flowing through each LED. The lower the resistance value, the brighter the LED will glow. Using higher wattage and/or finer tolerances is okay. |
1 |
10k 1/8W 10% resistor |
This is a pull-up resistor used with the push button switch. Any value in the neighborhood of 10k is fine; e.g., 12k or 15k is okay. Higher wattages and/or finer tolerances are acceptable. |
1 |
12 mm tactile switch |
A 12 mm tactile switch such as Sparkfun's COM-09190. In general, you will need a four terminal, SPST momentary "on" push button switch electrically and dimensionally equivalent to the Omron B3F-4000 series. Activating this switch causes the die to be rolled. Rolling continues until it is deactivated (released). |
1 |
0.1 μF capacitor, 12VDC |
Optional part which need not be installed. Any ceramic or similar capacitor with 2.5 mm lead spacing and a rating of at least 12VDC will suffice. |
1 |
2 × 3 pin header |
Optional part which only needs to be installed if you will program the AVR chip once it is in the circuit. A 2 × 3 or two 1 × 3 male pin headers with a 2.54 mm (0.1 inch) pitch. E.g., Evil Mad Science 6-pin DIL headers. |
1 |
2 × AA or 2 × AAA battery compartment with wire leads |
Most any receptacle for holding two AA or AAA batteries will suffice. It does not need to have an on/off switch as the AVR itself will go into a low power mode in which it consumes far less power than that lost to the natural self-discharge of a battery. That is, leaving the circuit turned on will not contribute significantly to the batteries running down. See, e.g., the Evil Mad Science 2xAA Battery Holder or Adafruit's Waterproof 2xAA Battery Holder. However, having an on/off switch is convenient if you will be reprogramming the AVR while it is in the circuit: it avoids having to remove the batteries. |
Assembly is straightforward with only a few items of note:
Once assembled, check your solder joints, preferrably with a magnifying glass. Touch up any suspect joints.
If the AVR has not been programmed, then do so now.
DO NOT APPLY BATTERY POWER TO THE CIRCUIT WHILE PROGRAMMING THE avr CHIP: THIS CIRCUIT DOES NOT INCLUDE ANY PROTECTION TO ISOLATE THE BATTERIES FROM THE PROGRAMMER. While programming, remove the batteries and use a programmer which supplies its own power (e.g., the USBtiny available from Evil Mad Science as well as Adafruit.)
Next, proceed to Section 6, Operation for directions on testing and using your new digital die.
Now things are getting interesting. This medium sized design has a nice form factor and two choices for enclosures: a commercial enclosure from New Age Enclosures and an enclosure you can customize yourself and print on a 3D printer. The circuit for the medium design is identical to that of the large design: refer to that design's schematic above or see the Eagle CAD file included with the source distribution.
Note that the medium sized PCB is designed to fit in New Age Enclosure's Mini AAA enclosure while remaining inexpensive. Hence those multiple drill hits at the bottom of the board: they avoid using internal routes while accomodating the tabs for New Age's battery contacts. Internal routes normally used to make such cutouts are often disallowed by the discount PCB pricing plans. Should you wish to order a PCB, please refer to Section 8, Ordering a PCB.
Before assembling the circuit board, it is best to have an enclosure ready. Having it availble during the board's assembly allows you to test fit components. It also makes it easy to install the LEDs at the correct height. So, let's being by discussing obtaining or printing an enclosure.
For an enclosure, you have two choices: buy one or print your own. If you have a 3D printer, then print your own as then you won't need to drill holes for the LEDs and push button. Otherwise, consider buying an enclosure as they give the project a professional finish, assuming you're handy with a drill.
The OpenSCAD source for the medium sized enclosure is the file src/scad/box-med.scad. The rendered STL files are src/scad/box-med-top.stl and box-med-bottom.stl. You should be able to use those STL files directly. However, if you have dimensional printing issues or wish to make changes, then you can alter the OpenSCAD source and re-render the STL files. See the very bottom of the OpenSCAD file to see how to selectively render just the top or bottom of the enclosure. (Hint: comment out the line you don't want.)
For screws, you will want two #0 self tapping screws, either 5/16 or 3/8 inches long. In metric, those would be 1.5 or 1.4 mm screws 8 - 10 mm long.
When slicing the .stl files for printing, use 100% infill and 3 or 4 shells. The use of extra shells helps prevent situations where the cylindrical posts may have their infill omitted by the slicer.
The Mini AAA enclosure from New Age Enclosures is quite nice and, in the USA is available from Mouser Electronics. To use their Mini AAA Enclosure, you will need one each of the following:
S3A-251510
| The Mini AAA enclosure itself |
ACC-AAAPOS-5226 |
Positive battery terminal |
ACC-AAANEG-5204 |
Negative battery terminal |
ACC-AAADBL-5214 |
Double battery terminal |
All of these parts are available from Mouser and other distributors of New Age Enclosures. Their assembly is illustrated in the 2D rendering of the enclosure available at New Age Enclosure's web site.
For this enclosure, you will need to drill eight holes in the top: seven for the LEDs and one for the push button. The PDF file eagle/dice-med-drill-guide.pdf may be used as a drill guide: print it, cut it out including the cuts for the enclosure's internal posts, tape it to the inside of the enclosure using the posts to ensure good registration, mark the eight points with an awl, and then drill with twist drill bits. The size of the bits will depend upon the size of your LEDs and push button. For best results, use a small drill bit and first drill from the inside of the enclosure lid. Then, with the correct finish size drill bit, enlarge the holes drilling from the outside of the lid.
To assemble the circuit, you will need the circuit board and the following components:
Quantity |
Component |
Usage / Description |
|---|---|---|
1 |
ATtiny2313 or 4313 |
The AVR microcontroller in a DIP package. The ATtiny4313 is available from Evil Mad Science as well as very nifty programming kits for out-of-circuit programming. Well worth considering if you plan to work with AVRs. |
7 |
3 mm LEDs |
Die "pips" (spots). Most any non-exotic, two wire LEDs with 2.5 mm lead spacing will work (e.g., red 3 mm LEDs). Consider whether or not you want LEDs with clear (as in water clear) lenses versus with tinted lenses. A die with red tinted lenses will look different than a die with water clear lenses when the LEDs are not illuminated. |
7 |
1.2k 1/8W 10% resistors |
Current limiting resistors to control the amount of current flowing through each LED. The lower the resistance value, the brighter the LED will glow. To improve battery life, don't go below 1.2k unless you really need to. Rather, consider using a higher resistance. Using higher wattage and/or finer tolerances is, of course, okay. |
1 |
10k 1/8W 10% resistor |
This is a pull-up resistor used with the push button switch. Any value in the neighborhood of 10k is fine; e.g., 12k or 15k is okay. Higher wattages and/or finer tolerances are acceptable. |
1 |
12 mm tactile switch |
A 12 mm tactile switch such as Sparkfun's COM-09190. In general, you will need a four terminal, SPST momentary "on" push button switch electrically and dimensionally equivalent to the Omron B3F-4000 series. Activating this switch causes the die to be rolled. Rolling continues until it is deactivated (released). |
1 |
0.1 μF capacitor, 12VDC |
Optional part which need not be installed. Any ceramic or similar capacitor with 2.5 mm lead spacing and a rating of at least 12VDC will suffice. |
1 |
2 × 3 pin header |
Optional part which only needs to be installed if you will program the AVR chip once it is in the circuit. A 2 × 3 or two 1 × 3 male pin headers with a 2.54 mm (0.1 inch) pitch. These are sold by most DIY electronics suppliers; e.g., Evil Mad Science 6-pin DIL headers. |
1 |
2 × AAA battery compartment with wire leads |
If you print your own enclosure with a 3D printer using the supplied 3D models, you will want a very compact 2 × AAA battery holder such as Digikey's BC2AAAW-ND. Alternatively, you can modify the enclosure design to accept a larger holder. -- OR -- If you use a Mini AAA enclosure from New Age Enclosures, then you will need a set of battery contacts. A set consists of one each of ACC-AAANEG-5204, ACC-AAAPOS-5226, and ACC-AAADBL-5214 (negative, positive, and double contacts).
|
The schematic for the medium board design is not electrically different from that for the large design. Refer to Section 3.0, Large design for the schematic, look at the actual Eagle CAD file, or click here to see the schematic.
Assembly of the board is straightforward, but there are some important points to be aware of:
Once assembled, check your solder joints, preferrably with a magnifying glass. Touch up any suspect joints.
If the AVR has not been programmed, then do so now.
DO NOT APPLY BATTERY POWER TO THE CIRCUIT WHILE PROGRAMMING THE avr CHIP: THIS CIRCUIT DOES NOT INCLUDE ANY PROTECTION TO ISOLATE THE BATTERIES FROM THE PROGRAMMER. While programming, remove the batteries and use a programmer which supplies its own power (e.g., the USBtiny available from Evil Mad Science as well as Adafruit.)
Next, proceed to Section 6, Operation for directions on testing and using your new digital die.
For an even smaller layout, we have the small PCB design which can fit in a Serpac CA4,2 key fob enclosure normally used for controlling a car alarm. Or, if you have access to a 3D printer, you can print your own enclosure using the 3D model distributed with this project's source code. As with the medium enclosure, it's easier to assemble the PCB when you have the enclosure prepared and ready to receive the board.
However, programming the AVR for this design is not as simple as the other designs. For this design, it is easiest to place the AVR into a breadboard and then use jumper wires from the breadboard to the female 2 × 3 header (or equivalent) of your programmer. Or, better yet, use an AvrUsb500 programmer from tuxgraphics.org: it's designed for use with breadboards.
Note that the push button in this design is placed off center so as to accomodate the commercial Serpac enclosure: that enclosure has two buttons of which only one is used.
You can either purchase an enclosure or print your own. If you print your own, you will not need to drill holes in the enclosure lid for the LEDs and push button. But, if you don't mind doing a little drill work then using a purchased enclosure is fairly straightforward.
The OpenSCAD source for the small enclosure is the file src/scad/box-small.scad. The rendered STL files are src/scad/box-small-top.stl and box-small-bottom.stl. You should be able to use those STL files directly. However, if you have dimensional issues or wish to make changes, then you can alter the OpenSCAD source and re-render the STL files. See the very bottom of the OpenSCAD file to see how to selectively render just the top or bottom of the enclosure. (Hint: comment out the line you don't want.)
When slicing the .stl files for printing, use 100% infill and 3 or 4 shells. The use of extra shells helps prevent situations where the cylindrical posts may have their infill omitted by the slicer.
For the printed enclosure, you will want a taller push button than for the Serpac CA4,2 enclosure. For screws, you will want two #0 self tapping screws, either 3/8 or 1/2 inches long. In metric, those would be 1.5 or 1.4 mm screws 10 - 12 mm long.
The CA4,2 enclosure from Serpac is available from Mouser Electronics. With this enclosure you need to use a low profile tactile push button. Note that only one of the two enclosure buttons will be used. The other button is unused.
With this enclosure, you will need to drill eight holes in the top: seven for the LEDs and one for the push button. The PDF file eagle/dice-small-drill-guide.pdf may be used as a drill guide: print it, cut it out including the cuts for the enclosure's internal posts, tape it to the inside of the enclosure using the posts to ensure good registration, mark the eight points with an awl, and then drill with twist drill bits. You may get the cleanest looking results by drilling each hole with a small bit from the inside of the lid to the outside. Then, using the correct, larger size bit drill from the outside to the inside. The size of the bits will depend upon the size of your LEDs and push button.
To assemble the circuit, you will need the circuit board and the following components,
Quantity |
Component | Usage / Description |
|---|---|---|
1 |
ATtiny24, 44, or 84 | The AVR microcontroller in a DIP package. The ATtiny24, 44, and 84 are available from Mouser, Digikey and other suppliers. They are most easily programmed on a breadboard using a programmer such as the AvrUsb500 from tuxgraphics.org. |
7 |
LEDs | Die "pips" (spots). Most any non-exotic, two wire LEDs with 2.5 mm lead spacing will work (e.g., red 3 mm T1 LEDs). Consider whether or not you want LEDs with clear (as in water clear) lenses versus with tinted lenses. A die with red tinted lenses will look different than a die with water clear lenses when the LEDs are not illuminated. |
1 |
1.2k resistor net, 6 pin | Three of the seven current limiting resistors. Note that this is a non-polarized resistor network. For this application, a polarized network in which all the resistors have a common leg could have been used; however, so doing would have introduced yet another polarized component. Bourns 4606X-102-122LF (Digikey 4606X-2-122LF-ND; Mouser 652-4606X-2LF-1.2K). Install on the underside of the PCB. |
1 |
1.2k resistor net, 8 pin | Four of the seven current limiting resistors. Note that this is a non-polarized resistor network. CTS 77083122P (Digikey 770-83-R1.2KP-ND; Mouser 774-77083122P). Install on the underside of the PCB. |
1 |
10k 1/8W 10% resistor | This is a pull-up resistor used with the push button switch. Any value in the neighborhood of 10k is fine; e.g., 12k or 15k is okay. Be careful about using a higher wattage value: you want a small resistor in order to fit the board. |
1 |
6 mm SMD tactile switch | A 6 mm, gull-wing surface mount tactile switch. If you will be using the Serpac CA4,2 enclosure, you need a low profile button such as TE Connectivity's FSM2JSMA (Digikey 450-1130-ND; Mouser 506-3-1437565-0). If you will be printing your own enclosure, you need a taller button such as the FSM6JSMA. |
1 |
0.1 μF capacitor, 12VDC | Optional part -- need not be installed. Any ceramic or similar capacitor with 2.5 mm lead spacing and a rating of at least 12VDC will suffice. |
1 |
1 × 6 female right angle header | Optional part -- only needs to be installed if you will program the AVR chip once it is in the circuit. A 1 × 6 female right angle pin header with a 2.54 mm (0.1 inch) pitch. For example, Sullins PPPC061LGBN-RC (Digikey S5481-ND). Install on the underside of the PCB before installing the AVR. |
1 |
20 mm battery clip | 20 mm coin cell battery clip such as Keystone Electronics 3003 (Digikey 3003K-ND; Mouser 534-3003). |
1 |
CR2032 |
3V lithium battery to power the circuit. |
The schematic for the small board design is not electrically different from that for the medium or large designs. Refer to Section 3.0, Large design for the schematic, look at the actual Eagle CAD file, or click here to see the schematic.
Assembly of the board is straightforward, but there are some important points to be aware of:
Once assembled, check your solder joints, preferrably with a magnifying glass. Touch up any suspect joints.
If the AVR has not been programmed, then do so now.
DO NOT APPLY BATTERY POWER TO THE CIRCUIT WHILE PROGRAMMING THE avr CHIP: THIS CIRCUIT DOES NOT INCLUDE ANY PROTECTION TO ISOLATE THE BATTERIES FROM THE PROGRAMMER. While programming, remove the batteries and use a programmer which supplies its own power (e.g., the USBtiny available from Evil Mad Science as well as Adafruit.)
Next, proceed to Section 6, Operation for directions on testing and using your new digital die.
When the die is powered on, one by one each of the seven pips will light up and remain lit. For a six-sided die, that's a non-existent die face. But it does serve to ensure that all the LEDs are functioning. If one or more LED is not functioning -- is not lit -- then odds are it is inserted backwards. Being polarized devices, they must be correctly oriented in order to work. (The voltages involved here are not sufficient to damage the LEDs should they be inserted backwards.) Remove (breadboard) or desolder the LED and correctly re-orient it. If the orientation is not at issue, then the solder joint of the limiting resistor and the AVR pins should be inspected.
Once everything is working correctly, power the die up. Note that if the die is left alone for 60 seconds, the AVR will enter a low power, standby mode and the LEDs will be turned off. Pressing the push button will awaken the AVR and again light each of the LEDs one by one.
Pressing and holding the push button will simulate a toss of the die. While the button is depressed, an animated light sequence will be displayed. The animation will continue until and briefly after the button is released, after which the result of the die toss is displayed. Pressing the button again initiates another die toss. After 120 seconds of inactivity, the display is turned off and the AVR enters its standby mode. This may be changed in the source code by adjusting the SLEEPY_TIME constant.
Note that the default build of the source code conserves power by rapidy alternating which LEDs are lit. If you quickly move the die about in a dark room, you may notice some flickering: that's normal.
For the Arduino build, use the sketch src/firmware/dice.pde and build it as you would any other Arduino sketch. If you are new to the Arduino environment, see Adafruit's collection of Arduino tutorials for a gentle introduction to Arduino.
For the C file src/firmware/dice.c, a "makefile" is provided. You will need an avr-gcc toolchain and you may need to change some of the definitions within the makefile, src/firmware/Makefile, in order to correctly reference the tools from your toolchain. Once the makefile is correctly set up, you can use it to build .hex files as well as programming your AVR with avrdude,
Microprocessor | Command to build the firmware | Command to program the AVR |
|---|---|---|
ATtiny2313, ATtiny4313 | make MCU_TARGET=attiny2313 |
make MCU_TARGET=attiny2313 program |
ATtiny24 | make MCU_TARGET=attiny24 |
make MCU_TARGET=attiny24 program |
ATtiny44 | make MCU_TARGET=attiny44 |
make MCU_TARGET=attiny44 program |
ATtiny84 | make MCU_TARGET=attiny84 |
make MCU_TARGET=attiny84 program |
If you are new to AVR programming, give Evil Mad Scientist Laboratories' tutorial Blink an LED with an AVR a read. Adafruit also has AVR programming tutorials: see the "Software/Programming" topic at the Adafruit tutorials.
The dice distribution includes the Eagle CAD files for each of the PCBs in the eagle/ directory. Also included are the Gerber and drill files for each PCB; see the gerber/ directory. Those files are in zip archives suitable for direct upload to the PCB fab of your choice,
Each of the designs has also been uploaded to batchpcb.com, manufactured, assembled, and tested. You can order them from batchpcb.com using the following URLs,
Note that the above URLs are for recent uploads of the designs with Open Source Hardware (OSHW) branding -- a mark which didn't exist in 2009 when I originally uploaded and ordered the boards from batchpcb.com. However, only the silk screens have been changed.