Dice Roller
A digital dice roller, controlled by Arduino. Each dice is represented by 7 LEDs that are arranged according to standard dice pip pattern.
There are two dice and one button. Pressing the button rolls the dice, displays a sequence of random numbers, followed by the result.
The LEDs are connected to the Arduino pins as follows:

Hardware
| Item | Quantity | Notes |
|---|---|---|
| Arduino Uno R3 | 1 | |
| 5mm LED | 14 | Red and Green |
| 12mm Push button | 1 | |
| Resistor | 14 | 220Ω |
Diagram
Pin Connections
| Arduino Pin | Part | Location |
|---|---|---|
| 2 | Red LED | Top-left |
| 3 | Red LED | Top-right |
| 4 | Red LED | Mid-left |
| 5 | Red LED | Center |
| 6 | Red LED | Mid-right |
| 7 | Red LED | Bottom-left |
| 8 | Red LED | Bottom right |
| 9 | Green LED | Top-left |
| 10 | Green LED | Top-right |
| 11 | Green LED | Mid-left |
| 12 | Green LED | Center |
| A3 | Green LED | Mid-right |
| A4 | Green LED | Bottom-left |
| A5 | Green LED | Bottom right |
| A0 | Button |
- The LEDs are connected through a 220Ω resistor each.
Video Tutorial
Source code
sketch.ino
// Arduino Dice Roller
// Copyright (C) 2020, Uri Shaked
#define BUTTON_PIN A0
const byte die1Pins[] = { 2, 3, 4, 5, 6, 7, 8};
const byte die2Pins[] = { 9, 10, 11, 12, A3, A4, A5};
void setup() {
pinMode(A0, INPUT_PULLUP);
for (byte i = 0; i < 7; i++) {
pinMode(die1Pins[i], OUTPUT);
pinMode(die2Pins[i], OUTPUT);
}
}
void displayNumber(const byte pins[], byte number) {
byte states = pins[0];
for (byte i = 0; i < 7; i++) {
digitalWrite(pins[i], LOW);
}
switch (number) {
case 1:
digitalWrite(pins[3], HIGH);
break;
case 2:
digitalWrite(pins[0], HIGH);
digitalWrite(pins[6], HIGH);
break;
case 3:
digitalWrite(pins[0], HIGH);
digitalWrite(pins[3], HIGH);
digitalWrite(pins[6], HIGH);
break;
case 4:
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[5], HIGH);
digitalWrite(pins[6], HIGH);
break;
case 5:
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[3], HIGH);
digitalWrite(pins[5], HIGH);
digitalWrite(pins[6], HIGH);
break;
case 6:
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[2], HIGH);
digitalWrite(pins[4], HIGH);
digitalWrite(pins[5], HIGH);
digitalWrite(pins[6], HIGH);
break;
}
}
bool randomReady = false;
void loop() {
bool buttonPressed = !digitalRead(BUTTON_PIN);
if (!randomReady && buttonPressed) {
// Use the time until the first button press
// to initialize the random number generator
randomSeed(micros());
randomReady = true;
}
if (buttonPressed) {
for (byte i = 0; i < 10; i++) {
int num1 = random(1, 7);
int num2 = random(1, 7);
displayNumber(die1Pins, num1);
displayNumber(die2Pins, num2);
delay(50 + i * 20);
}
}
}