Skip to content
03micro:bit ยท MakeCode 25 minutes

Shake-to-roll dice

Use the motion sensor to roll a random number from 1 to 6.

Shake-to-roll dice project
Illustration of the finished idea. Build from the diagram and connection table, not the photo.

Lesson goal: Use the shake gesture and randint(1, 6) to make an electronic dice.

Open MakeCode

Section 1

Understand

  • accelerometer
  • gesture event
  • random number
  • inclusive range
  • 1The accelerometer senses motion.
  • 2On shake, pick a random number from 1 to 6.
  • 3Show it on the display.

Safety first

  • Shake gently over a table or soft surface, holding the cable so the board cannot fly off. Do not throw the board.