Lesson at a glance
maze.education/microbit/lessons/dice
- Grades
- Grades 4 to 6
- Time
- 45 to 60 minutesThe CAPS gives Coding and Robotics 2 hours a week (Coding and Robotics CAPS, Grades 4 to 6, page 22).
- Level
- Getting startedA good first or second micro:bit lesson. No coding needed before.
- Board
- Any micro:bit
- Code with
- MakeCode and Purple Mash blocks, with Python as an extension
- CAPS
- Mathematics, Coding and RoboticsAligned: Grade 6, Term 2 · Where it fits
Learning intentions
Learners will learn to:
- Use a variable and a random number to make a digital dice.
- Record the outcomes of repeated rolls in a tally table.
- Compare the results with what a fair dice should give.
Success criteria
Each learner can say:
- I can explain what pick random 1 to 6 does, and why the number is kept in a variable.
- I can build a dice that shows a number from 1 to 6 each time I shake it.
- I can record 60 rolls in a tally table.
- I can compare our results with about 10 of each number, and say whether the dice seems fair.
Competencies
From the Coding and Robotics CAPS places this lesson cites.
- R.6Mimic the operations of a robot
Key words
- random
- Chosen by chance, so you cannot predict it.
- variable
- A named box in the computer's memory that holds a value.
- outcome
- One possible result, such as rolling a 4.
- tally
- Marks in groups of five used to count results.
- fair
- Every outcome has the same chance of happening.
- IPO table
- A plan with three columns: the input, the processing and the output.
What you need
- One micro:bit per pair, with a USB cable and a battery holder
- A computer with Chrome or Edge for each pair
- A dice per pair (a real one, or one folded from a paper net), and a tally table with rows for 1 to 6
From our shop: BBC micro:bit V2 Go, BBC micro:bit V2.21 Next Gen Classroom Pack
Safety
- Shake the micro:bit with the battery holder held firmly in the same hand, so neither flies off.
- Use the battery holder with two AAA batteries. Never mix old and new batteries, and take the batteries out before the kits are packed away.
- Unplug the battery holder by holding its plug, never by pulling the wires.
The lesson plan
One lesson of 45 to 60 minutes in three parts: introduction, lesson development and consolidation. The CAPS gives Coding and Robotics 2 hours a week, so it fits one of the week's lessons. Times are a guide.
Introduction
5 to 10 minutesRetrieval practiceWhat are two inputs the micro:bit can sense? (Buttons A and B, a shake or a tilt, light and temperature.)
Problem statementThe school's board-game club keeps losing its dice under the tables at aftercare. Build a dice on the micro:bit that cannot roll away, and test whether it is as fair as a real one.
- Roll a real dice a few times. Ask: can anyone say what comes next? Why not? Agree that the outcome is random.
- Read the problem statement together. Ask: if we roll 60 times, how many sixes would you expect? Write the predictions on the board.
Lesson development
35 to 40 minutes- Unplugged first. Pairs roll a real dice 30 times and tally the results. Keep the tables for the consolidation, to compare with the micro:bit dice.
- Plan on paper first. Pairs fill in an IPO table for the dice: what goes in, what the micro:bit does with it and what comes out. Then they write the algorithm as numbered steps.
- Predict. Before anyone runs the program, each pair writes down what they expect to see after three shakes, and whether the same number can come up twice in a row.
- Build in blocks. Pairs share one computer. The driver builds the dice from the steps on the Blocks tab; the navigator holds the paper plan, reads out each step and checks each block against it. Swap roles halfway, after step 4. Point out the variable roll: it holds the number until the next shake.
- Test and debug. Test in the simulator with the SHAKE button. Did it match your prediction? If it shows 0 or never changes, find the fault in the common mistakes, then download it.
- Pairs roll the micro:bit dice 60 times: one shakes, the other keeps the tally. Total the class results for each number on the board.
Plan on paper: a model answer
In pairs, fill in an IPO table for the dice, then write its algorithm as numbered steps.
Algorithm
- Wait for a shake.
- Pick a random number from 1 to 6.
- Store it in roll.
- Show roll on the display.
- Wait for the next shake.
IPO table
Input Processing Output The micro:bit is shaken Pick a random whole number from 1 to 6 and keep it in the variable roll The number in roll shows on the display Consolidation
5 to 10 minutes- Compare the class totals with the real dice tallies: are the six numbers roughly equal? Did anyone predict well?
- Ask: why do 30 rolls look uneven, while the class total looks fairer?
- Back to the problem: is the micro:bit dice fair enough for the board-game club? How could we find out for certain? Learners check themselves against the success criteria.
Build it, step by step
Pairs build the program in blocks, following the numbered steps, with the same program as text beside them to check against or paste. Test in the simulator before sending it to a board.
These are the MakeCode steps. The other routes are on the lesson's web page.
Build it in MakeCode blocks
- Start a New Project called Dice.
- From Variables, click Make a Variable and call it roll.
- From Input, drag on shake onto the workspace.
- From Variables, drag set roll to 0 into on shake.
- From Math, drag pick random 0 to 10 into the 0 and change it to 1 to 6.
- From Basic, add show number under it, and from Variables drag the round roll block into it.
- Test with the simulator's SHAKE button, then Download.
let roll = 0
input.onGesture(Gesture.Shake, function () {
roll = randint(1, 6)
basic.showNumber(roll)
})To use the text instead: open MakeCode, start a new project, click JavaScript at the top, replace what is there with this code, then click Blocks to see it as blocks.
To send it to the board, click Download. In Chrome or Edge, MakeCode can connect to the micro:bit by USB so the program goes straight onto it. Otherwise a .hex file downloads: drag it onto the MICROBIT drive.
Purple Mash follows the UK school years, which run about one grade ahead of ours: Year 3 is roughly Grade 2 here, Year 4 roughly Grade 3 and Year 5 roughly Grade 4. 2Simple says its micro:bit lessons can be adapted for other ages, so older learners who are new to the micro:bit can use them too.
These steps are our own. 2Simple's lesson has its own plan, slides and videos, which teachers with a Purple Mash login can use alongside this one.
Our steps in Free Code micro:bit
Block names in Free Code micro:bit are not the same as MakeCode's, so these steps say what each block does. Check the exact names in Purple Mash.
- Log in to Purple Mash and open the lesson from the Computing Scheme of Work, or the micro:bit projects in the Computing area. They use Free Code micro:bit, 2Simple's block coding tool for the micro:bit (2Simple's help pages also call it 2Code micro:bit).
- Open Free Code micro:bit from the Making a Dice lesson.
- Add the shake event, so the dice rolls when the board is shaken.
- Inside it, choose a random number from 1 to 6 and show it on the display. Check in Purple Mash which block picks a random number.
- Test it on the emulator.
- Test the program on the on-screen micro:bit (2Simple calls it the micro:bit emulator) before you send it to a board.
- Save your work, open the purple menu at the top and choose Download.Hex. Plug in the micro:bit with a USB cable that carries data and drag the .hex file onto the MICROBIT drive. On an iPad, open the file in the micro:bit app and tap Send to micro:bit.
2Simple says the micro:bit projects can also be coded in Python in Pieces, if your school has it.
Extension: text-based coding, beyond the CAPS
The same program in MicroPython, for the micro:bit Python Editor. It suits Grade 7 to 9 learners who are ready for text-based code. The CAPS itself follows a block-based approach (Coding and Robotics CAPS, Grades 7 to 9, page 24).
# Shake-to-roll dice: a random number from 1 to 6 on every shake.
from microbit import *
import random
while True:
if accelerometer.was_gesture("shake"):
roll = random.randint(1, 6)
display.show(roll)
sleep(100)Open the Python editor, replace the code that is there with this program (or open the downloaded file), then click Send to micro:bit. MakeCode also has a Python view, which is written a little differently.
Extension or homework
Challenges for learners who finish early, or to take further in a club or as homework.
- Challenge 1
Make a dice for a board game you know that needs a different number, such as 1 to 12 or 1 to 20.
- Challenge 2
Roll two dice at once (A for one, B for the other) and record the totals. Which total comes up most often, and why?
- Challenge 3
Turn the dice into a decision maker: shake, and it shows yes, no or maybe.
- Challenge 4
Make it a musical die, like the one in the Grade 6 CAPS: play a different note for each number on the micro:bit V2's built-in speaker.
Support and extension
Support
For learners who need more help
- Use a ready-made tally table with the numbers 1 to 6 already written in.
- Roll 30 times instead of 60, and compare with a partner's table.
Extension
For learners who are ready for more
- Draw real dice faces with show leds inside an if block for each number.
- Work out the percentage of rolls that gave each number, and compare it with one sixth (about 17%).
Informal assessment
Ask these as learners work. Informal assessment happens every day and is not recorded.
- What does pick random 1 to 6 do?
- Why do we store the number in a variable?
- After 60 rolls of a fair dice, about how many of each number would you expect?
Is getting three sixes in a row impossible? Explain.
Observation checklist
Watch pairs as they plan, build and test. Write each pair's initials under the level you see.
| Watch for | Beginning | Developing | Accomplished | Exemplary |
|---|---|---|---|---|
| Fills in the IPO table before building: a shake in, a random number processed, a number out. | ||||
| Builds the dice as the driver, or checks each block against the plan as the navigator. | ||||
| Predicts before testing, and compares the result with the prediction. | ||||
| Tallies 60 rolls accurately and compares them with about 10 of each. |
- Beginning:
- not yet, even with help
- Developing:
- with help
- Accomplished:
- on their own
- Exemplary:
- on their own, and explains it or takes it further
The four levels are the CAPS rubric levels (Coding and Robotics CAPS, Grades 4 to 6, page 176). The short descriptions are ours.
This lesson is not a formal task, but it is good practice for the term's practical task in Grades 4 to 6 (Coding and Robotics CAPS, Grades 4 to 6, page 170).
Common mistakes and fixes
- The dice shows 0 sometimes.The random block still says 0 to 10 or 0 to 6. Change it to 1 to 6.
- It always shows the same number.Check the show number block uses the roll variable, not the number 0.
- Nothing happens when we shake it.Check the event block says shake, and shake a little harder.
Where it sits in CAPS
- Coding and RoboticsAlignedGrade 6, Term 2: shake the micro:bit to roll a number from 1 to 6 (the CAPS musical die).Source: Coding and Robotics CAPS, Grades 4 to 6, Grade 6, Term 2, Robotics, R.6 Mimic the operations of a robot, page 144:
Shake a microcontroller to display a random number between 1 and 6 that can be used as a die.
- MathematicsGrades 4 to 6 Mathematics: probability experiments, such as rolling a die, repeated many times.Source: CAPS Mathematics, Grades 4 to 6, Section 2, topic 5.4 Probability (Grades 4, 5 and 6):
Perform simple repeated events and list possible outcomes for experiments
Coding and Robotics quotes come from the Department of Basic Education's final CAPS, with the page number of the 2024 printed edition (the Department's October 2025 library copies number their pages differently). Schools may teach a topic in another term: the CAPS leaves the order to each school's annual teaching plan.
micro:bit is a trade mark of the Micro:bit Educational Foundation, and BBC is a trade mark of the British Broadcasting Corporation. Maze Education is an independent reseller of genuine BBC micro:bit products. Our teacher training and our other products and services are our own, and are not endorsed by the Foundation or the BBC.

