Digital Dice Roller

Project Overview
This project demonstrates how to build a Digital Dice Roller using an Arduino Nano and an SSD1306 OLED display. With a press of a button, a random number appears on the screen — simulating a dice roll from 1 to 6 (or higher if using a potentiometer).
Ideal for beginners, this project introduces:
- I²C communication
- OLED graphics
- Random number generation
- Analog input handling (with potentiometer)
Supplies

What You Need
- 1 × Arduino Nano (or Uno/Mega)
- 1 × SSD1306 OLED Display (I²C type, 128x64)
- 1 × Pushbutton
- 1 × 10kΩ Resistor (optional if using INPUT_PULLUP)
- 1 × Breadboard (optional, for prototyping)
- 1 × Potentiometer (optional, for adjustable range)
- Jumper wires
Wiring the Components


Connect the SSD1306 OLED Display (I²C)
For Arduino Nano or Uno:
- VCC → 5V
- GND → GND
- SDA → A4
- SCL → A5
For Arduino Mega:
- VCC → 5V
- GND → GND
- SDA → Pin 20
- SCL → Pin 21
Connect the Pushbutton
- One terminal of button → GND
- Opposite diagonal terminal → D9 (Digital Pin 9)
Connect the 10kΩ Resistor
- One end of resistor → D9
- Other end of resistor → 5V
💡 This creates a pull-up resistor for the button. You can skip the external resistor if you use INPUT_PULLUP mode in code.
(Optional) Connect the Potentiometer (for adjustable dice range)
- Middle pin (wiper) → A0
- One outer pin → 5V
- Other outer pin → GND
Scan the OLED's I²C Address
Most SSD1306 OLEDs use address 0x3C, but some use 0x3D. Let’s scan it just to be sure.
Upload this scanner code:
Open Serial Monitor
Note the address it finds
Upload the Dice Roller Code


🎲 Basic Dice Roller (Fixed Range: 1 to 6)
Try this out first before moving on to the advanced version.
Add Adjustable Max Value (Potentiometer)




Now let’s add a potentiometer to dynamically control the dice’s max value. Want a D20 or D100? You got it.
🚀 Final Tips:
- Add an LED or buzzer for sound/light feedback!
- Want animations? Use the OLED’s graphic functions.
- Build a dice box with a display window!
Conclusion
This project provided a hands-on learning experience by covering core topics such as I²C communication, which allows the Arduino and OLED display to exchange data with just two wires, significantly simplifying the circuit. We also explored OLED graphics, learning to programmatically control pixels to display text and shapes, from simple numbers to rolling squares.