My Cart:

0 item(s) - £0.00
You have no items in your shopping cart.

Inventors Kit Experiment 12 Full Experiment

In this tutorial you will find Experiment 12 Making a random dice for the Kitronik Inventors Kit for the BBC micro:bit. This is an additional experiment to the ten that were included with the Inventors Kit, and has been created for you to get more from your kit. You will learn how to build the circuit and how to code the BBC microbit to control the circuit.

bbc micro:bit experiment-12-make-a-random-dice-main-870

You can complete the Inventors Kit Experiment 12 with or without the Inventors Kit. If you do not have the Kitronik Inventors Kit you will have to source all of the required components separately, a full list of the things you will need can be found below. We also advise the use of a breadboard as trying to complete this experiment with crocodile leads would be more than a little challenging.

You can download this experiment as a PDF here.pdf_icon.gif


This Experiment Requires:


The Aims Of This Experiment Are:

  • To make a dice using seven LEDs.
  • To use the ‘Pick Random’ number block.


Experiment 12 Video Walk Through:



Experiment 12 Making A Random Dice:

This experiment will create a random electronic dice. The numbers the dice display will be created by seven LEDs on the breadboard, arranged in the layout seen on the six sides of a real dice. The code will make use of the ‘pick random’ block to generate a random number when button A is pressed on the BBC micro:bit. Depending on the value of this random number the relevant LEDs on the breadboard will be lit up.


The Microsoft Block Editor For The BBC micro:bit:

This experiment is created using the Microsoft Block Editor.

The Microsoft Block Editor is a drag and drop visual editor that provides a simple introduction to programming. Blocks snap together to build programs and are grouped by the type of function they do. When a group is selected the commands in that group are shown and can be selected.

microbit experiment-12-make-a-random-dice-blocks-870


Create The Following Code:


If you're having difficulty producing your own code for this experiment, we've created the code for you that you can compile, download and place onto your BBC microbit. To get the code, follow this link.

To use the above code; Follow the link above and select Edit. Press the Compile button and the code will be compiled and will automatically download via your browser. Plug your BBC micro:bit into a USB slot on your computer, your computer will now see the micro:bit as a removable drive. You can drag the downloaded hex file directly onto your micro bit. On some systems the hex file may not show up as being on the micro:bit, but it is there.


Building This Circuit On The Prototyping System:

It is possible to build this circuit using the Prototyping System for the BBC micro:bit and the components listed at the top of the page. Once you have sourced the required parts you can follow the diagram below.



What Will Happen?:

Press and release button ‘A’ on the BBC micro:bit. A random number should now be displayed on the LEDs on the breadboard. Try pressing the button a number of times to make sure all six of the possible numbers can be displayed.


Circuit Diagram: 



What's Going On?:

Firstly the ‘on button A pressed’ block is used to determine when button A has been pressed on the BBC micro:bit and a new dice number needs to be calculated and displayed. Pressing the button causes the ‘item’ variable to be loaded with a random number between zero and five, which is generated by the ‘pick random’ block. The ‘item’ variable then has one added to it so that it will be in the range one to six (one of the numbers on a dice).

Once the random number between one and six has been calculated all of the LEDs are turned off (to clear the last number) and the ‘item’ variable is then checked by an ‘else if’ block and this causes the LEDs needed to display that number to be turned on.

The relationship between the number that is to be displayed on the dice, the LEDs that need to be lit up, and the pins that control them, are shown in the table on the opposite page.

So, for example, if the number 3 was to be displayed on the dice, this would require LEDs 1, 2 and 3 to be lit. These are controlled by pins P0 and P1 (P1 controls LEDs 2 and 3). As the cathode of the LEDs are permanently connected to 0V (GND), the LEDs are turned on by taking the associated BBC micro:bit pin high. This creates a voltage across the LED(s) and turns it/them on.


Inventors Kit Experiment 12 Code Examples:


Extension Tasks:

  • Can you make the dice work using the ‘On Shake’ command?
  • Can you make the LEDs flicker while the button is being pressed?


You can download this experiment as a PDF here.pdf_icon.gif


Kitronik Inventors Kit Resources:


Exp No#. Experiment Name. Resource Type.
1 Say Hello to the BBC micro:bit. Further Help.
2 Using an LDR and analog inputs. Full Experiment + Further Help.
3 Dimming an LED using a potentiometer. Further Help.
4 Using a transistor to drive a motor. Full Experiment + Further Help.
5 Using the accelerometer to control motor speed. Further Help.
6 Setting the tone with a piezo buzzer. Further Help.
7 Wind Power. Full Experiment + Further Help.
8 Making a game using the compass. Further Help.
9 Capacitor charge circuit. Further Help.
10 Using an RGB LED. Further Help.
11 Making a pedestrian crossing. Full Experiment + Further Help.
12 Making a random dice. Full Experiment + Further Help.


Get The Kitronik Inventors Kit For The BBC microbit:

We do two versions of the Inventors Kit for the BBC micro:bit, with or without the BBC micro:bit included. Chose the option that is right for you from the links below.

← Previous Post Next Post →

Leave a Reply