Project tutorial
Smart DICE: The Physical + Digital RNG

Smart DICE: The Physical + Digital RNG © CC BY

An electronic dice that does not take away the thrill of the roll. The motion data from a roll generates a random number shown on LED's.

  • 8 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project


The idea for this project originally came from this Kickstarter for an LED Dice - Luma Dice. I play a variety of board and card games and most of them include a dice of some sort. When playing with friends, I end up whipping out a phone and running a dice app on it. This however takes away from the visceral joy of rolling the dice and watching it settle to my desired value.

So I wanted to design an electronic design that took the randomness of the rolling motion and used that as a source of entropy to generate a result. On the plus side compared to a physical multi-hedral dice this electronic version does not need to be a specific shape, a simple cube or 8-ball enclosure will do. The actual value shown is determined by the code, as is the case in a phone app.

I received the FRDM K82F Arduino shield compatible board from NXP as part of their contest and it has all the peripherals needed to make my project a reality.

Stepping through RGB Led display in preparation for the 7-segment display


The first step was getting some LED's blinking with the board. The demo code on the FRDM K82F comes with support for the built in LED's on Pins 8, 9 and 10 of port C. I decided to drive the entire 7-segment LED display which will show the dice output via Port C as well to reuse the existing codebase. The video above shows stepping through the code in Kinetis Design Studio to cycle through the LED's.

The accelerometer reading code is also already implemented in the bubble demo. I experimented a bit by showing the LSF(least-significant-figure) of the readings on a seven segment display, this proved to be not random enough.

The other method of generating True Random Numbers (TRNG) on the FRDM board is provided as a sample in the SDK. This method uses a ring oscillator (series of oscillating NOT gaets) on the SoC as an Entropy source and after a certain delay produces a string of random bits which pass statistical checks.

The 2 random numbers (from accelerometer noise and ring oscillator) can be combined to generate stronger ones.


There are several papers on using accelerometers as an Entropy source. One of the earlier works was done using RFID cards and more recently using phone accelerometer with long term filtering to remove adversorial tampering. The implementation here is relatively simple, it combines 2 samples of the LSB of the accelerometer readings and 1 sample of the TRNG generated data using bitwise-XOR operation.

640 CPU cycles are used for ring oscillator entropy accumulation and 10cycles are used between accelerometer readings to allow decorrelation of successive reads.

The "physical + electronic" dice keeps rolling as long as the board is off near horizonal position as measured by accerometer x and y readings. The dice fixes on a value once the board become horizontal.

I also included a battery charger shield from SeeedStudio to allow operation away from the computer and USB ports. This shield allows connection of solar panels for long term use. This mode of operation is illustrated the video below.

Triggering Random Numbers with tilt/shakes


To finish off the project I built a cardboard enclosure using Pepakura.

This type of enclosure allows me to choose a theme according to any game I might be playing.

This project also makes a great toy for school age kids learning their numbers. A digit is shown on shaking the dice and the challenge is to quickly name it. It functions as a flash card for larger numbers, additional digits can be included by dedicating an enable pin per digit to increase the degree of challenge in the game.

I am getting the Adafruit NeoPixel Shield for more flexibility in number display.


FRDM-K82F Accelerometer Dice
This is the firmware for the board. Clone from git, import project into Kinetis Development Studio and deploy to the board over USB using Segger Jlink.

Custom parts and enclosures

Dice Shaped Enclosure
Enclosure shape for FRDM K82F dice, scale it suitably and 3D-print or build with card stock and Pepakura


Arduino proto board wiring
This is an image of the protoboard clearly showing the pins on Port-C of the Kinetis MCU used to drive the 7-segment display
K82f dice


Similar projects you might like

Smart Battery Charger Multiplexer with Smart Display

Project tutorial by leonzak

  • 25 respects

MicroView Digital Dice

Project tutorial by Giovanni Gentile

  • 1 comment
  • 2 respects

Smart Dice Tower with Arduino [Board Game Assistant]

Project tutorial by ElectroPeak

  • 0 respects

Arduino Digital Dice

Project tutorial by tylerpeppy

  • 13 respects

Variable-Sided Digital Dice

Project tutorial by Isabellaw55

  • 1 comment
  • 1 respect

Smart Home - Smart Rules using ARTIK Cloud & Photon

Project tutorial by Raghavendra Ponuganti

  • 18 respects
Add projectSign up / Login