Digital Dice with Microbit | Fun STEM Coding Activity (2026)
Digital Dice Using Microbit (Micro:bit ) : Overview
The Digital Dice project is a beginner-friendly STEM activity that teaches programming and electronics using the BBC Micro:bit and Microsoft MakeCode. Instead of rolling a physical dice, the Micro:bit generates a random number from one to six whenever it is shaken. Students explore event-driven programming, variables, random number generation, and LED displays while creating an engaging interactive application. This project encourages computational thinking and helps learners understand how simple algorithms control hardware devices. It is suitable for Grades 5–8 and can be extended with animations, sounds, score counters, and wireless communication.
Materials Required for Digital Dice
- BBC Micro:bit
- USB cable
- Computer or laptop,
- Internet connection,
- Microsoft MakeCode editor.
Learning Objectives
- Understand variables
- Events
- Random numbers
- LED output
- Testing
- Debugging,
- Embedded programming.
Detailed Step-by-Step Coding
Step 1: Create Project
Open Microsoft MakeCode and create a project named Digital Dice. The workspace contains an On Start block that runs once when the Micro:bit powers on.
Step 2: On Start
Use Basic -> show icon (Happy). This confirms the program has started.
Step 3: Variable Declaration
Open Variables, click ‘Make a Variable’, and create DiceNumber. A variable is a named memory location that stores data. Initially it has no meaningful value until assigned.
Step 4: Input Event
Drag Input -> on shake. This event waits continuously for the accelerometer to detect a shake.
Step 5: Generate Random Number
Inside on shake, drag ‘set DiceNumber to’. From Math insert ‘pick random 1 to 6’. Every shake creates a new random integer from 1–6 and stores it in DiceNumber.
Step 6: Display
Drag Basic -> show number and place DiceNumber inside. The stored value appears on the LED matrix.
Step 7: Pause
Add pause 500–1000 ms so users can read the value.
Step 8: Clear
Add clear screen to prepare for the next roll.
Block Logic
The program starts, shows a happy icon, waits for a shake event, generates a random value, stores it in Dice Number, displays the value, and waits for another shake. Using a variable makes the program easier to expand with score counters or statistics later.
Expected Output
Each time the Micro:bit is shaken, a new random number between one and six appears on the LED display. The board remains active and can be shaken repeatedly without restarting the program.
FAQs
-
Why is a variable needed?
The variable stores the random number generated by the program. Using a variable makes it easier to display the value, keep score, or add more features later.
-
Why use On Shake?
The On Shake event detects movement using the Micro:bit’s accelerometer. When the board is shaken, it automatically runs the code to generate and display a random dice number.
-
Why use Pick Random?
The Pick Random block generates a random integer between the specified values (1 and 6). This ensures each dice roll has an equal chance of appearing, just like a real dice.
-
Can I display LED dots?
Yes! Instead of displaying numbers, you can use the Show LEDs block to create traditional dice faces with dots, making the project look even more like a real dice.
-
Can I add sounds?
Yes. If you’re using Micro:bit V2, you can use its built-in speaker to play sounds whenever the dice is rolled. You can also connect an external buzzer for additional sound effects.
-
Can I count rolls?
Absolutely! Create another variable called Roll Count and increase it by 1 every time the Micro:bit is shaken. Then display the total number of rolls whenever needed.
Conclusion
The Digital Dice using the BBC Micro:bit is an engaging and interactive STEM project that introduces students to the exciting world of programming, electronics, and embedded systems through a simple real-life application. By replacing a traditional dice with a programmable digital device, students gain hands-on experience in understanding how software controls hardware to perform useful tasks. Throughout this project, learners explore essential programming concepts such as variables, event-driven programming, random number generation, LED display control, and sequencing, while also developing computational thinking and logical reasoning skills.
The Digital dice project demonstrates how the Micro:bit’s built-in accelerometer can detect movement and trigger actions automatically. When the board is shaken, the program instantly generates a random number between one and six, stores it in a variable, and displays the result on the LED matrix. This practical activity helps students understand how sensors, algorithms, and electronic components work together to create interactive embedded applications.
Beyond learning coding fundamentals, this project encourages creativity, experimentation, and problem-solving. Students can test different programming ideas, debug their code, modify the LED display, add animations or sound effects, maintain score counters, or even transmit dice values wirelessly using the Micro:bit’s radio feature. These enhancements help learners build confidence while introducing them to more advanced topics such as robotics, Internet of Things (IoT), and wireless communication.
Overall, the Digital Dice project provides an excellent foundation for beginners who are starting their journey in coding and electronics. It successfully combines mathematics, programming, and technology into a fun and meaningful learning experience. By completing this digital dice activity, students not only understand the principles behind random number generation and embedded programming but also develop valuable STEM skills that can be applied to future projects involving automation, smart devices, robotics, and real-world engineering solutions. This project inspires curiosity, innovation, and a deeper appreciation for how programmable technology can transform simple everyday objects into intelligent interactive devices.
Real-World Applications
Digital random number generation is used in games, educational toys, simulations, security testing, and decision-making applications. Similar programming concepts appear in robotics and IoT devices.






