Kids' Basics: Electronic Dice

Using an Arduino Uno

Dean Corva

Issue 35, June 2020

This article includes additional downloadable resources.
Please log in to access.

Log in

Replace your boring plastic game dice for this fun electronic version - simply shake and the number will show on the 7 segment LED display. Learn about Arduino and 7-segment LEDs at the same time.


Ever been in a situation where setting up a board game has come to halt because the dice isn’t in the box? Well, don’t pack up that game up just yet, let’s build an electronic dice instead!

Using an Arduino Uno as the main brains for the electronic dice, minimal components are needed to get the electronic dice to operate. Most electronic dice available on the internet are a bit boring so we’ve designed and programmed one from scratch to make the end result more interesting and interactive for kids. We’ve constructed two different methods depending on how interactive you want the end solution. We'll first build the dice and have it operate using a pushbutton, and then we'll show you how to add on a motion sensor so you can start the dice when you shake it! Cool!

We’re assuming very little (or zero) electronics knowledge, and so will try to walk through everything carefully, in order to ensure your success. Basic computer skills are assumed (as is access to a computer, with an internet connection, to use the software). If you have trouble following any of the software installation steps, then you may like to seek further assistance from a family member or friend.


You will need to have an Arduino Uno or compatible board, and the Arduino IDE application installed on your computer. The Arduino IDE is where we will load code, and compile it onto your Arduino Uno board. You can download the application for free from Follow the prompts to install it on your Windows, Mac, or Linux based computer.

With your Arduino connected to your computer via USB, go to Tools › Board and ensure Arduino / Genuino UNO is selected, or the appropriate board for what you are using.

Then also select Tools › Port and click on the one that shows USB. The precise wording will depend on your operating system.

In order to load code onto your Arduino board, open the Arduino IDE once installed.

Go to File › Open and select the file noted in the article (Each file is within a folder of the same name).


We have already written the code you need for this project and made it available on our website for you to download. Go to our website and find this project. At the bottom of the page, there will be a link to download the file. Note: You will need to log in to the website to download the file. Registering is free.


We have provided you with a list of electronic parts you need to build this project, along with any tools and craft items you may need. Some cardboard cutting is required, so adult supervision may be required.

1 x Computer running Windows, OSX or Linux
1 x Thick cardboard
1 x Pair of Strong Scissors
1 x Hobby Knife
1 x Roll of Sticky Tape
1 x Roll of Double-Sided Tape


ELECTRONIC Parts Required:JaycarAltronicsCore Electronics
1 x Arduino Uno or Compatible BoardXC4410Z6280 or Z6240A000066 or CE05629
1 × Solderless BreadboardPB8820P1002CE05102
10 x Plug-to-Plug Jumper Wires*WC6024P1016PRT-12795
12 × Wire Links*PB8850P1014ACE05631
1 x 7-Segment Common Cathode LED DisplayZD1855Z0190-
8 x 220Ω Resistors*RR0556R7542COM-10969
1 x Push ButtonSP0601S1120COM-00097
1 x Shock SensorXC3732-BOB-13926
14 x Plug-to-Socket Jumper Wires*WC6028P1017PRT-12794
1 x 2.1mm DC plugPA3711P0608AFIT0110
1 × 9V Battery SnapPH9230P0455CE05205
1 × 9V BatterySB2423S4970BCE05337
1 x Push ButtonSP0601S1120COM-00097

ELECTRONIC Parts Required:

* Quantity required, may only be sold in packs.


If you have not used a breadboard before and want to learn more about them, see our Breadboarding Basics article from Issue 015.

We have included what is called a Fritzing diagram to show you how to wire up the electronics onto your breadboard. If you want to know more about Fritzing diagrams, see our The Basics of Fritzing article in Issue 016.

The Electronics Build:

The dice is simplistic in design, requiring only a 7-segment LED display, a single pushbutton, a few resistors, and interconnection wires.

Set up with Push Button Activation:


Place the breadboard in front of you so that the upper rail, facing away from you, is red; while the lower rail, closest to you, is blue. Following the row numbers on the breadboard, insert the 7-segment display into rows 1 to 5 with the dot on the 7-segment display facing to the right of the breadboard.


Insert eight 220Ω resistors (red-red-brown-yellow or red-red-black-black-brown) into rows 19 to 26.


Insert the push button into rows 28 to 30.


Using interconnecting wires, connect the following rows to the bottom side of the 7-segment display (the side of the dot): Row 26 to 5, row 25 to 4, row 24 to 2, and row 23 to 1.


Using interconnecting wires again, connect the following rows to the top side of the 7-segment display: Row 22 to 5, row 21 to 4, row 20 to 2, row 19 to 1.


Using interconnecting wires, connect both sides of row 3 and row 28 to the negative rail (-) on the breadboard. Be sure to connect both negative sides together on the breadboard if you use both sides as we have.


Using plug-to-plug jumper wires, connect pins 2 to 9 of the Arduino to rows 26 to 19 on the breadboard. Also, connect GND of the Arduino to the negative rail of the breadboard.

TIP: Keep the nine wires joined together from new if possible to make the final project much neater.


Using a jumper wire, connect pin 10 of the Arduino to row 30 on the breadboard. That’s it for the hardware! Now onto the coding.


Download the Method 1 code ‘ElectronicDice_Method1.ino‘ from resources. We need to load this code into your Arduino Uno using the following steps. Plug in the Arduino Uno to your computer with the Arduino IDE installed and running. Open the code file by selecting File › Open, find and select the ‘ElectronicDice_Method1.ino‘ file saved on your computer, then press Open.

Press the Upload button (or Sketch > Upload) from the menu to upload the method 1 code to the Arduino Uno.

Note: If you receive errors doing so, ensure you followed the board setup steps on the first page under “Software Prerequisites”. This will eliminate the majority of issues you may have if you’re not familiar with the Arduino software.


Pressing the pushbutton on the breadboard will initiate a roll. The Arduino selects a random value between 1 to 6, then produces a fun rolling pattern on the 7-segment display to simulate the dice rolling, then displays the result on the 7-segment display.

The previous number will be displayed until the push button is pressed again.


Changing constants TopRollSpeed and BottomRollSpeed in the code will change the time it takes for the fun rolling pattern to operate. So if the roll time is too long, reduce TopRollSpeed and if the roll isn’t long enough increase TopRollSpeed.

// Constants
#define TopRollSpeed 50
#define BottomRollSpeed 10

Add Shake Activation:

This project replaces the single pushbutton with an impact sensor, where shaking the sensor initiates a roll. We also enclose the hardware in a small cardboard box to make a clean solution, making it much more interactive and fun to use!

Note: We will keep the pushbutton on the breadboard even though it will no longer work in this build.

STEP 1: Using plug-to-socket jumper wires, connect the socket side to GND, VCC, SDA, and SCL of the sensor.

STEP 2: Connect the plug side to the Arduino with GND to GND, VCC to 5V, SDA to SDA (A4), and SCL to SCL (A5).

Download the Method 2 code from the DIYODE website (if not done so already). Connect your Arduino Uno to your computer and have the Arduino IDE application running. For our Arduino Uno to work with the tilt sensor we need to install what is called a library. Open the Sketch menu, select Include Library, select Manage Libraries, search for “Sparkfun MMA8452Q Accelerometer by Sparkfun Electronics” in the search box, then click on Install.

Upload the Method 2 code by going to File > Open, find and select the 'ElectronicDice_Method2.ino’ file on your computer, then upload that to your Arduino Uno.


Shaking the enclosure will now initiate a roll. Much cooler than the previous push button method! Now, let’s make it look pretty and portable by mounting it in a box and powering it using a battery.

The Box Construction:


Remove the 7-segment display from the breadboard. Using plug-to-socket jumper wires, connect the socket side of the jumper wires to the pins of the 7-segment display, and then connect the plug side to the breadboard, in the position where the 7-segment display was removed.


Connect the red wire of the 9V battery connector to the positive of the 2.1mm screw terminal adaptor. Connect the black wire of the 9V battery connector to the negative of the 2.1mm screw terminal adaptor.


Cut out two pieces of cardboard using scissors, to 100mm x 300mm.


Carefully cut out a hole for the 7-segment display on one of the pieces, 50mm down from the top with a hole 20mm x 10mm.


Fold the two cardboard pieces into thirds, or every 100mm. Stick the pieces together as shown here.


Using double-sided tape, mount the breadboard to the bottom of the enclosure.


Mount the Arduino board to the side of the enclosure with double-sided tape.


Use double-sided tape to mount the sensor to the side of the box. (Orientation doesn’t matter).


Insert the 7-segment display in the cutout.

STEP 10:

Mount the battery to the side and plug the 2.1mm plug into the Arduino.

STEP 11:

Close the box using one piece of tape to easily open the box again.

Note: If you’re worried about the electronics in the case coming loose, just fill in with some tissue or some soft non-conductive material to pad it out.


Hopefully, this build inspires kids and makers to add additional options to the build such as a larger display or different colour display. A cool build would be to add a 7-segment display to each face of the enclosure, so instead of shaking the dice, you could roll the dice! Make the enclosure more appealing by colouring it in or making it look like a dice by drawing dots on it!

In this build, we used a red 7-segment display. The total current draw of the 7-segment display is 90mA using the 220Ω (Ohm) resistors. This is below the maximum current draw of each pin and overall of the Arduino, however, if you use a different colour display or a larger display, or more displays, don’t exceed the maximum limits of the Arduino. Otherwise, additional hardware is needed.

Now back to playing the board game. Good luck!

Dean Corva

Dean Corva

Staff Writer