r/microbit • u/elecfreaks_official • 2m ago
We Built a Lucky Spinner That Spins Randomly but Always Knows Where to Stop 🎯
We wanted to make a simple prize spinner with micro:bit, but there was one thing we didn't want to compromise on: the spinner could be random, but its final position had to be accurate.
So we built this four-way Lucky Spinner using a PlanetX Smart Brick Motor and parts from the ELECFREAKS Nezha Pro Sport Kit.
There are four possible results: a blue ball, a red ball, a black-and-white soccer ball, and an orange-rimmed soccer ball. Each one represents a number from 1 to 4. When the red pin at the end of the spinner arm points toward one of them, the micro:bit displays the corresponding number.
The interesting part is how the program handles the spin.
Before the first draw, we point the arm toward the blue ball and press Button B. The program saves the motor's current absolute angle as the reference position for Result 1. It doesn't matter whether the motor is physically at 0° or not. What matters is that the program now knows which direction represents the starting point.
When we press Button A, two random values are generated:
- A result between 1 and 4.
- A number of full rotations between 3 and 5.
The motor spins at full speed, completes the selected number of rotations, and then moves to the calculated target angle. Since the four prize positions are 90° apart, the program can work out exactly where the arm needs to stop.
For example, if the selected result is 3, the arm needs to finish 180° away from the calibrated starting position. Even if the spinner makes a different number of full rotations each time, the final direction still matches the selected result.
We also added a short delay before showing the number. Once the arm stops, the program waits 0.5 seconds and then displays the result for three seconds. After that, the number disappears and the standby icon comes back. The program temporarily ignores new button presses while a draw is in progress, so the next spin can't interrupt the current one.
I like this project because it brings together a few programming ideas in a very visible way: random numbers, motor angles, calibration, and program states. You can actually see the difference between choosing a random outcome and physically moving a mechanism to the correct position.
It's a small project, but getting the mechanical direction and the on-screen result to agree is what makes it satisfying to watch.
Would you add sound or LED effects to make the final reveal more dramatic?