Make a micro:bit Shake Dice

In this activity, students create a digital dice by programming the micro:bit to detect a shake gesture and respond by displaying a random number between 1 and 6 on the LED screen. The micro:bit uses its built-in accelerometer to detect the shake motion, which acts as the input that triggers the number generating program.

Grade Levels: 3 - 12
Subject Matter: Algorithms, Physical Computing, Programming, Cross-Curricular Integration: Math
Concepts: Programs and Algorithms, Computing Devices and Systems, Data and Information
Standards: 3-5.PA.3, 3-5.CD.2, 6-8.CD.2, K-2.PA.1, K-2.PA.2, K-2.PA.3, K-2.PA.4, 3-5.PA.2, 6-8.CD.3, 6-8.PA.1, 6-8.PA.2, 6-8.PA.3, 3-5.DI.1, 6-8.DI.1, 6-8.DI.2, K-2.CD.2, 3-5.CD.1
  • Average Rating: 0.0 (0 ratings)

Materials

Activity Instructions

  1. Introduce the Activity
    • Have you ever rolled a dice and wondered if it’s truly random?
    • Can a computer be random?
    • Today, we are going to program a micro:bit to act as our own digital dice.
  2. Introduce the Concept
    • A dice gives a random number from 1 to 6. How will we do that with the micro:bit
    • Explain:
      • Computers use a random function to simulate randomness
      • The micro:bit will:
        • Detect a shake using a built in sensor called the accelerometer.
        • Generate a random number 1-6
        • Display it
        • Build the Code
  3. Model in MakeCode:
    • Add the following blocks:
    • on shake block
    • Inside, add:
      • show number
      • Replace number with:
      • pick random block (1 to 6)
    • Walk students through creating the code or use the provided link to share the completed code with students.
  4. Test the Dice – Let’s roll your dice!
    • Students download test their code on the micro:bit
    • Shake micro:bit
    • Observe numbers
      • Discuss:
        • Do the numbers seem random?
        • What if you have the same number several times in a row? Is that possible? Why?
        • Investigate Randomness
        • Let’s test if it’s really random.
        • Activity:
          • Roll micro:bit dice 20–30 times
          • Record results in a tally chart
          • Compare results to real dice outcomes
            • Discuss: Which number appeared most?
              Were they evenly distributed?
  5. Discuss Findings
    • Did your dice behave randomly?
    • Why might some numbers appear more often?
    • Is computer randomness perfect?
  6. Reflection – Discuss:
    • What triggered your program?
    • How did the micro:bit generate a number?
    • What surprised you about the results?

Extension Opportunities

Students can:

  • Create two-dice simulation (2–12 total)
  • Display dot patterns instead of numbers
  • Add sound effects when rolling
  • Design a game using their dice
  • Investigate probability of sums (2–12)

Elements of this resource were created by BBC micro:bit, then curated by the team at Nextech.

Learn More