Introduction: Digital Dice

I have always wanted to make my own dice for table top games but it would be difficult to make them balanced. I realized that a digitalized die wouldn't have this problem. Then I realized that an electronic die would be capable of having multiple "sides". Instead of using a set of seven separate dice (1d4, 1d6, 1d8, 1d10, 1d12, 1d20, 1d100), I could combine all of these into one, hence the Digital Dice. The display for the Digital Dice would have to always face up after being rolled so I did some research on such a shape. If you would like to know more, a gömböc is a shape that will always right itself . Due to its somewhat complex shape, I decided to opt for a roly-poly design instead. The weights on the bottom make sure that it will always land face up.

The interface is simple, one switch and one knob. The switch is used to turn it on/off. The dial is used to select the type of die to be used. Gently rolling the Digital Dice will trigger the rolling sequence and after a few seconds, a number will be displayed. The code in this Instructable is set to eight selections, 2, 4, 6, 8, 10, 12, 20, and 100 sides. When you are selecting the amount of sides, the number will be displayed. The decimal points light up to indicate that the number shown is the number of faces not a rolled number.

Step 1: Components

Things that you will need:

  • Arduino Micro (Arduino Nano should also work)
  • Soldering iron and solder
  • Hot glue gun
  • 9V battery
  • 9V battery connector
  • 10kΩ potentiometer with long knob
  • Resistors (1 MΩ, 2 x 470 Ω)
  • Slide switch
  • Tilt sensor
  • Two digit seven segment display, found here on Amazon
  • ~18 pennies
  • Wires (about 22 gauge should be fine)
  • Paperclip
  • Small box or 3D printer to print container
  • Magnets (optional)

The Arduino runs the code for this project. If you are making the Digital Dice in a compact container like I did, you will need a small Arduino such as the Micro (this is what I used). The 9V battery is the largest component and the Arduino Micro just so happens to have a similar, yet slightly smaller length and width so it is the perfect candidate for this project. I used a 9V battery because it is the most convenient way to power an Arduino. If you don't have a 9V battery connector you can solder the wires directly to the battery.

The potentiometer is used to select the amount of sides the die will have. It is important that the knob is long enough to be easily adjusted by hand. Many potentiometers require a screwdriver to adjust so try to avoid those. I used a 10kΩ potentiometer but others would work as well. The higher the resistance the better because this will lower the power consumption.

The resistances of the resistors does not need to be the exact value that I listed. The listed values were the ones that I used. One of the resistors just needs to have a high resistance to minimize power consumption. I would suggest using the highest value resistor that you have. Anything above 1 kΩ is fine. The other two resistors should be the same value as each other, 220Ω < R < 680Ω should be fine. A lower resistance corresponds with a brighter display and higher power consumption.

The tilt sensor is used to detect when the die is rolled. Some seven segment displays have different pin layouts, so keep this in mind if you use one different from the link. The one on Amazon has 10 pins. The 18 pennies are used as weights to ensure that the display always points upwards after being rolled. Unfortunately, if you don't have a 3D printer you will have to be creative and make your own case. The magnets are used to keep the two halves of the die together. If you don't want to get these, you can simply use a dab of hot glue to secure the two halves together. It will be inconvenient if you need to open up the die though if you don't use the magnets.

Step 2: Wiring

Before soldering the wires, it is a good idea to test out the seven segment display on a breadboard first to make sure that you have the correct pinout for the display. Some displays have a different pinout than the one in this Instructable. You can also test out different resistor values to find a suitable brightness for the display. A resistance between 220 and 680 Ω will work well. One resistor should be connected to pin 5 and one to pin 10. Pin 5 is the common pin for the ones digit and pin 10 is the common pin for the 10s digit. Refer to the second picture for how the two digit seven segment display works.

The wires connecting the components to the Arduino should be fairly short so everything can be packed tightly in the container. I used liquid electric tape to cover the exposed wires to prevent anything from accidentally shorting out. Regular electrical tape will work as a suitable substitute.

Step 3: Code

There are two things that may need to be changed in the code for the program to work correctly. The pin numbers on lines 20-31 will have to be changed if you did not connect each component to the same pins that I used in the wiring diagram. If you followed the wiring diagram exactly as it is shown you do not have to change this part.

The second thing that will most likely need to be changed are the analog input values on lines 106-113. First determine how many options you want to be able to choose from. The code is currently configured so you pick from 8 different values, 2, 4, 6, 8, 10, 12, 20, and 100. For example, If you want to add a 13 sided die to the list simply add the following line of code between 12 and 20 (after line 111).

else if (dice < X) dice = 13;

Next you will have to change the value of X. The value of X is the raw value that analogRead outputs. X can be any integer from 0-1023.

  1. Find the minimum and maximum values that the potentiometer produces. See the Arduino website if you are not familiar with using the analogRead function. For me, my range of values was about 0-96.
  2. Now take the difference between the minimum and maximum values and divide that by the amount of options possible (8 for me).
  3. X should be a multiple of this number. For example, you have 5 options and the min and max values from analogRead are 0 and 50. (50-0)/5 = 10, so the first value is 10, the next is 20, and so on. See the code below for this example.
if (dice < 10) dice = 4;
else if (dice < 20) dice = 6;
else if (dice < 30) dice = 8;
else if (dice < 40) dice = 10;
else dice = 12;

This will equally space out the options over the full range of the potentiometer. Note that I had a resistor in series with my potentiometer so that lowered my range of values to 0-96. I did this to lower the power consumption but this also made the analog to digital conversion more susceptible to switching between options if the value was right on the border.

Here is the pseudocode if you are curious:

Setup pins (lines 43-56)
Check selection on dice (60)
If different selection then display new selection (61-72)
Check for roll (75)
If rolled do the following: (78)
Pick a random seed for the random number generator (79-80)
Pick a random number from 1 to the value on the selection (81-85)
Show waiting display for 3 seconds to give the die time to settle (90-93)
Show randomly determined number (94-97)

Step 4: Assembly

The most challenging part of this project was getting everything to fit into the 3D printed piece. I made the dimensions large enough to accommodate everything but, like I said, it is a tight fit. I would recommend soldering all of the wires before you insert the components into the casing. Soldering irons don't fit in tight spaces very well and will easily melt the ABS/PLA plastic. Try to figure out the orientation of each piece before you solder so you have an idea of how long the wires should be and where they have to go. Make sure to cut the wires on the longer side if you are unsure so you have some extra wiggle room for placing the parts.

After all of the soldering is compete, make sure to cover up all of the uninsulated wires as much as possible. When everything is crammed together, wires can easily short out. I would highly recommend liquid electrical tape because it will make this project much easier. Regular electrical tape is fine too but it doesn't work quite as well for thin wires. You could use a hot glue gun to insulate the wires too. Make sure that every exposed wire is covered as much as possible. On the first prototype that I made, I think something shorted out on it. Short-circuits are the most likely (and most frustrating) cause for things to go wrong in this Instructable. However, as long as you are careful, you shouldn't have a problem.

After you have double-checked the wiring and covered all of the wires, the next step is to use the hot glue gun to hold the parts in place. Make sure that the display, the tilt sensor, the switch, and potentiometer are all well secured. Also, make sure to keep glue away from the potentiometer knob. The tilt sensor should be positioned facing upwards* (it is normally closed, so when it is tilted, the circuit is open). I didn't glue in the Arduino because I wanted to be able to easily access the USB port to reprogram the Arduino if necessary. I used some hot glue on the longer wires as well to prevent them from getting in the way.

If you are 3D printing your casing:

Glue the pennies to the bottom half of the casing. Use plenty of glue so they don't come loose. When you install the magnets, be VERY careful of the direction that you glue them in. I used superglue for the magnets but the hot glue might work too. I had all of the magnets on each half in the same orientation. So for example, on the top half, the north side of the magnets was exposed. On the bottom half, the south side of all of the magnets was exposed. Don't forget about the two magnets that hold the battery in place on the bottom half. You should have a total of 4 magnets on the top and 6 magnets on the bottom. Two magnets are used to help hold the battery in place.

Cut two straight ~1 inch long segments from a paper clip. These will be used to prevent the two halves from rotating. I put a strip of electrical tape along the top of the battery so the Arduino can't touch the metal casing. Plug in the battery and you should be good to go!

* If the Arduino is "rolling the dice" when it is upright and not moving, change line 78 to read as follows:

if (accelerometer == HIGH) {

This would happen if you installed the tilt sensor differently from what I did (facing down).

Let me know if you have any questions about this project, I'll do my best to get back to you.

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017