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

IMG_3730.jpeg

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

81kROvJlDhL.jpg

Arduino Nano : https://www.amazon.ca/-/fr/CANADUINO-Module-Nano-Atmega328-CH340/dp/B01FV7NIUA?source=ps-sl-shoppingads-lpcontext&ref_=fplfs&psc=1&smid=A29AOP4GIE7DX6


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


Push Button: https://www.amazon.ca/C-J-SHOP-Miniature-Momentary-Tactile/dp/B01CGMP9GY/ref=sr_1_6?dib=eyJ2IjoiMSJ9.1DrSMRCOTjaMqOycbTYD7TuCJh3E6n9hrbPo8TXFMeOOwu1U6WOesn8JZDhWB1MfRYBnoibzZ9ZOyinVqyhwrOKW4RKu_qqqBnjn0fWJdJp_YdqUGqmHUkJ3QHMrvCK6OUM2H4N8iz_Y6nxIviBYaTW9thprGfh8xBzGvmFl2feMw0JbN-eSfjyXWgjXuSWp4z5Dr5uvtz1nkO7DpSEe2lnXCqZniif6HOqjAGbVIEDXx-ujFkum-Oig3XGNj9Dpo4_g101Sh1jqA3JlObzYgeo-946c79u2iGRPmj8D3BE.sunO2W81HS4Jjx85hYtU_u_4ChstO20K2R-ALAdfTSA&dib_tag=se&keywords=arduino+push+button&qid=1781825105&sr=8-6


Slide Switch: https://www.amazon.ca/Switch-Position-Vertical-Microphone-Circuit/dp/B0DRXG76PG/ref=sr_1_6?crid=EM0TFEY8D2FA&dib=eyJ2IjoiMSJ9.bbW_b83RNI4g9H1xBtJUXNCtcjkBpL8AMdFiLvNr__EZm-CVE97IE0iEoM1_CYaWDXC_ZI54w7DhtKh_P9u6Ht67_uNW7Wy3ExcnaCqz55jw7MeD08-lKc156Ra3Ah1WJBE1Bf1llt4LF6W2S4ZhipTw0qVBSVqCA7C0hg6e0mjIxEOcJoo0PVFVKo3kiRPLQJJI8suXWnUiaV3nkgDCJiTAe_iK-Rr9phmkQYtzaKq_plhOkH4D4g1TCpXPD3MRMX1w2OjGGLAoe2VEHHZt4KxEoBJ2vqmoAxoZCqwpjwY.gC6SdBgHyLY-a0Z2K4FMhyeMtW3zx11mUHW1YBpRb-Y&dib_tag=se&keywords=slide%2Bswitch&qid=1781825154&sprefix=slide%2Bswitch%2B%2Caps%2C122&sr=8-6&th=1


Buzzer: https://www.amazon.ca/Cylewet-Electronic-Magnetic-Continous-Arduino/dp/B07DDK92F5/ref=sr_1_5?dib=eyJ2IjoiMSJ9.GoYKky-hOpW48moA76GayGKlT6zF-8eRkS1q2W9ZLzPVCqaPUuhTGlM8Sd6i6-h4QVRqNsCwCMGOt9Qnq23CMGhvz4sB1Kw7RFqnHpBnUfKtxehL78lkJCl1L2FgefnM9wypi6p8AGFIOROsPnAYMj9MG8fN5qGGPUZBBMcuK6FDfFGUVDWxMiMVxqbrQFEMkiYtAGctnCv_cwx3IqDFYWWu_062pce5RtQ5nxf6SreOHGPOlsL1e0q-6fSk1ltBcpl1PSOxTYL5p4Gq3WX9GZbnSL3li2bSM-Xlz-Czfs4.HK2yRtFTgxrr0hwH9jN9FA4oHq1Ple-_mWcgw5YUhS8&dib_tag=se&keywords=arduino+buzzer&qid=1781825226&sr=8-5


Wires: https://www.amazon.ca/EDGELEC-Breadboard-Optional-Assorted-Multicolored/dp/B07GD2BWPY/ref=sr_1_2_sspa?crid=CZ14623VRW7O&dib=eyJ2IjoiMSJ9.P0SXZ5zZTHkPo09W9gnDTChUvmaWI1aq5UNivxEhz5BMXmDjsLkCk8GZot9fdZLOncX2DnXLyDJESoISsfMejPrsHfM33tOsZsbnKmk-rYYG-ZuzJzqrCVh7QlJF-hO1Q2dc0VCkbmxAqqjWBSPYZ0c61JwsgJAgQj19acBdCblGyFqAQ_cvto-bAX-2Awruq5WKbh7JoVoJH66bi_J8cGZjikB72goz_UZ1Zs5r2W1b0nIIS7G77AKr2QPAJzdhoS1aeok3eVD4BVuP56loD2AXjYmJXXcUE_WrWMA4KQE.GVWuw_kiyXTB1QhsS7ITa5TUod-xL7t66ownxikzjA4&dib_tag=se&keywords=arduino%2Bwires&qid=1781825263&sprefix=arduino%2Bwires%2Caps%2C114&sr=8-2-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&th=1



System Overview

IMG_3700.jpeg

This project works as a complete embedded system:

Input:

  1. Push button (triggers roll)
  2. Slide switch (mode selection)

Processing:

  1. Arduino Nano generates random number using analog noise seed
  2. Converts number into binary format

Output:

  1. MAX7219 LED matrices (visual display)
  2. Buzzer (audio feedback)


Wiring

IMG_3730.jpeg

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

images (8).jpeg

https://app.arduino.cc/sketches/aa4618b7-a277-4196-9b9c-f30c94e1f47f?view-mode=preview

Code Explanation:

Library + LED Setup

#include <LedControl.h>
LedControl lc = LedControl(11, 13, 10, );
  1. Uses LedControl library to control MAX7219 LED matrices
  2. LED matrices connected (DIN=11, CLK=13, CS=10)

2. Pins

buttonPin = 2
switchPin = 3
buzzerPin = 6


3. Variables

diceValue = 1
lastButtonState
  1. Stores current dice number
  2. Tracks button press to avoid repeat triggers

4. Dice Faces

  1. 6 patterns (1–6)
  2. Each pattern = 8 rows (8×8 LED grid)
  3. Binary values = LED on/off design

5. setup()

  1. Sets pin modes
  2. Initializes all 4 LED matrices
  3. Sets brightness + clears display
  4. Seeds randomness
  5. Shows initial dice

6. loop()

  1. Reads button
  2. Detects press (HIGH → LOW)
  3. Calls:
  4. rollDice()
  5. displayCurrentMode()

7. rollDice()

  1. Runs animation (10 quick random faces)
  2. Beeps buzzer during roll
  3. Picks final random number (1–6)
  4. Plays final tone

8. displayCurrentMode()

  1. Clears screen
  2. Shows dice face
  3. If switch ON → also shows binary mode

9. drawDice()

  1. Sends correct dice pattern to LED matrix 0

10. drawBinary()

  1. Converts dice number into binary
  2. Lights different matrices based on bits

11. fillMatrix()

  1. Turns an entire LED matrix ON (solid block)

12. clearAll()

  1. Turns off all 4 matrices


Final Product

images (9).jpeg