
A simple electronic dice replaces a physical cube with seven LEDs arranged in the familiar dot pattern, rolling a random number from 1 to 6 with a satisfying animated spin at the press of a button.
Components needed
An Arduino Nano, seven LEDs, a tactile push button, resistors, and a breadboard.
Wiring it up
The seven LEDs connect to digital pins 2 through 8, arranged physically in the classic six-sided-die dot layout. The push button connects to analog pin A0, used here as a simple digital input.
How the roll is generated
Pressing the button triggers Arduino's random() function to pick a number between 1 and 6. To get genuinely unpredictable results run after run, randomSeed() is seeded using a reading based on microsecond timing — a value that varies enough between button presses to avoid the same "random" sequence repeating every time the board resets.
Displaying the result
A dedicated function lights only the LEDs that correspond to the chosen number's dot pattern — one center LED for a 1, two diagonal LEDs for a 2, and so on up through all seven LEDs lit for a 6. Before settling on the final number, the code cycles rapidly through several intermediate values with increasing delays between each, creating a spinning, slowing-down animation that mimics the feel of a real die coming to rest.
Where this is used
Beyond board games, this kind of button-triggered random-number display fits any project needing a simple randomizer — a decision-maker gadget, a game-night accessory, or just a fun first project for practicing button input and the random() function.
You can find LEDs and push buttons at Juthour Tech.
Leave your comment