This is a electronic game dice based on Arduino. I saw various schematics with discrete components or IOs more than twenty years ago, but this one with Arduino is easy and fun to make.
- Random number generation (1-6), the result is displayed on LEDs in a regular 6-sided dice style.
- Makes nice sound and animation when button is pressed.
- Silent mode - press the button during startup to mute all sounds.
- Sleep mode - activates after a period of inactivity.
The electronics is actually pretty simple. It uses 9 digital I/O pins on the Arduino:
D8 to control LEDs
D9 to connect the roll button
D10 to connect the piezo buzzer
See the 123D Circuits project or the following schematics:
ARD_top.stl part first, so you can start to work on LEDs, while printing the
ARD_bottom.stl part, which is bigger.
Push the LEDs into the sockets. The part is designed to hide most of the body, leaving just the curved tip visible. You can use CA glue (superglue) or hot glue to fix them, but the friction itself should be good enough.
Solder all the cathodes (shorter leads on LEDs) together and solder a wire to them.
Solder one 330 ohm resistor to cathode on one end and a length of wire on the other end.
Take 8 STL pins and solder the wires to the pins. First pin is ground (the cathodes), pins 2-8 are the LEDS in the order specified in the image below (when seen from top). You can also solder directly to PCB, if you don't want to test on breadboard.
Use tape or heat shrink to isolate the leads.
- Connect the STL pins to pins
D8 of the Arduino.
- Connect the button between pin
- Connect the buzzer between pin
You can use solderless breadboard or prototyping PCB, as you like.
Test setup on breadboard (resistors are hidden under heat-shrink)
TestHardware.ino sketch to Arduino and run it.
If you wired the pins correctly, the device should beep and then wait for button press. After a button press, the LEDs 1-7 should light one by one in the sequence given above and with each one shortly "click".
If you passed this test, you are basically done, you can load the
ArDice_V3.ino sketch, put it all into a nice box and enjoy. The rest of steps describes the software development process for interested.
Sequential LED test
TestNumbers.ino sketch contains definition of number symbols. The definition is specified in binary form, as a number, where each bit corresponds to single LED. The most significant bit is ignored (is always 0 in this case), because we have only 7 LEDs, thus need only 7 bits.
for loop in the
showNumber function sets the state of each LED according to the definition of number symbol.
The sketch is very similar to
TestHardware.ino, but does not blink single LEDs, but displays numbers from 1 to 6.
Number symbol test
Functional dice - first version
ArDice_V1.ino sketch is basic functional dice. Upon pressing a button, it will display animation of random numbers, finally settling on the definitive value.
We initialize random number generator by reading noise on unconnected analog pin
A0. That's not the best possible solution and we should not use it for example for cryptographic purposes, but it's good enough for a game dice.
Add sleep mode with breathing
ArDice_V2.ino sketch extends the previous version by adding timeout (30 seconds) after which the dice will 'sleep'. It will turn off the LEDs and only use the center one (LED 4, connected to pin
D5) to 'breath', glow with limited and varying intensity (using PWM) to indicate the project is alive.
Add silent mode
ArDice_V3.ino sketch is the final version. It extends the previous version by adding ability to turn off all sounds. To mute all sounds, press the button while turning on the dice