Example Code for micro:bit-Lucky Number
Last revision 2025/12/31
This article guides you through creating a Lucky Number game using micro:bit, involving hardware setup, software preparation, wiring, and executing sample code to display random numbers with interactive LED and buzzer feedback.
Hardware Preparation
- Math & Automatic expansion board for micro:bit, Quantity: 1
- micro:bit, Quantity: 1
- Buzzer, Quantity: 1
Software Preparation
Makecode graphical programming, Mind+ platform.
Makecode Library Address.
About how to install a software library?
Wiring Diagram
Buzzer is integrated on the board.
Other Preparation Work
Install the Makecode library from https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?
Sample Code

Lucky Number Example Codes Download
Result
Shake the expansion board, then one of the 15 RGB LEDs "jump" up and down, and the buzzer makes "jump down sound". At last, the LED will stops at a key. The corresponding key number will be displayed on the micro:bit LED matrix. This is your lucky number. Shake the board again, you can get the another one.
Was this article helpful?
