Electronic Dice on Arduino Nano That Shows Binary Output Too
by Tharush U in Circuits > Arduino
21 Views, 0 Favorites, 0 Comments
Electronic Dice on Arduino Nano That Shows Binary Output Too
Hello, my name is Tharush Uthayananthan.
For this project, I built an electronic dice using an Arduino Nano and four MAX7219 8X8 LED matrices. The purpose of this project is to simulate rolling a standard six-sided die while also teaching how decimal numbers are represented in binary.
When the push button is pressed, the Arduino generates a random number from 1 to 6. The left LED matrix displays the dice face, while the remaining three matrices display the binary representation of that number. A slide switch allows the user to change between displaying only the dice or displaying both the dice and the binary output. A buzzer provides audio feedback whenever the dice is rolled.
This project combines Unit 3 (Binary Logic) with Unit 4 (Arduino Microcontrollers) by using binary numbers, digital inputs, digital outputs, functions, loops, and programming to create an interactive learning device.
Supplies
CANADUINO 8×8 MAX7219 LED Matrix Module : https://www.amazon.ca/CANADUINO%C2%AE-64-Dot-Matrix-MAX7219-Module-Cluster/dp/B07B2JZ8VD
CANADUINO 830-Point Solderless Breadboard: https://www.amazon.ca/CANADUINO-Solderless-Breadboard-Adhesive-Detachable/dp/B072K5183D
System Overview
This project works as a complete embedded system:
Input:
- Push button (triggers roll)
- Slide switch (mode selection)
Processing:
- Arduino Nano generates random number using analog noise seed
- Converts number into binary format
Output:
- MAX7219 LED matrices (visual display)
- Buzzer (audio feedback)
Wiring
The wiring for this is quite straightforward as this is very minimal
Component ( top ) Arduino Nano pin ( below )
1) MAX7219 DIN
D11
2) MAX7219 CLK
D13
3) MAX7219 CS
D10
4) Button
D2
5) Slide switch
D3
6) Buzzer
D6
7) GND
GND
8) 5V
5V
Code
https://app.arduino.cc/sketches/aa4618b7-a277-4196-9b9c-f30c94e1f47f?view-mode=preview
Code Explanation:
Library + LED Setup
- Uses LedControl library to control MAX7219 LED matrices
- LED matrices connected (DIN=11, CLK=13, CS=10)
2. Pins
3. Variables
- Stores current dice number
- Tracks button press to avoid repeat triggers
4. Dice Faces
- 6 patterns (1–6)
- Each pattern = 8 rows (8×8 LED grid)
- Binary values = LED on/off design
5. setup()
- Sets pin modes
- Initializes all 4 LED matrices
- Sets brightness + clears display
- Seeds randomness
- Shows initial dice
6. loop()
- Reads button
- Detects press (HIGH → LOW)
- Calls:
- rollDice()
- displayCurrentMode()
7. rollDice()
- Runs animation (10 quick random faces)
- Beeps buzzer during roll
- Picks final random number (1–6)
- Plays final tone
8. displayCurrentMode()
- Clears screen
- Shows dice face
- If switch ON → also shows binary mode
9. drawDice()
- Sends correct dice pattern to LED matrix 0
10. drawBinary()
- Converts dice number into binary
- Lights different matrices based on bits
11. fillMatrix()
- Turns an entire LED matrix ON (solid block)
12. clearAll()
- Turns off all 4 matrices
Final Product