Electronic dice with seven LEDs
Build it step by step
0 of 5 doneLay out the dots
Place seven LEDs in the dice pattern: two columns of three plus one in the centre.
Wire each dot
D2 to D8 through 330 Ω to each LED's long leg, in the order listed. Short legs to GND.
Add the button
D12 to GND.
Upload and roll
Press the button. The dots flicker, slow down and stop.
Check fairness
Roll 60 times and tally the results. Each number should come up roughly 10 times.
How do you build an electronic dice with seven LEDs?
Press the button and seven LEDs laid out like dice dots roll, slow down and stop on a random number from one to six. You need Arduino Nano, LED 5 mm red × 7, Resistor 330 Ω × 7, Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 5 steps and about 45 minutes.
- Level
- Beginner
- Time
- About 45 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 1
- SemiconductorsBuyLED 5 mm red × 7
- PassivesBuyResistor 330 Ω × 7
- SwitchesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LED layout | Top-left, top-right, middle-left, centre, middle-right, bottom-left, bottom-right | Dice dots |
| Nano D2 to D8 | 330 Ω and one LED each, cathodes to GND | Seven dots |
| Button | Nano D12 and GND | Roll |
Code
Arduino IDE, board "Arduino Nano". No extra libraries.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Dots: 0 top-left, 1 top-right, 2 middle-left, 3 centre, 4 middle-right, 5 bottom-left, 6 bottom-right
const int PIN[7] = {2, 3, 4, 5, 6, 7, 8};
byte faces[7]; // bit i set = dot i lit
void show(int n) { for (int i = 0; i < 7; i++) digitalWrite(PIN[i], bitRead(faces[n], i)); }
void setup() {
for (int p : PIN) pinMode(p, OUTPUT);
pinMode(12, INPUT_PULLUP);
faces[1] = 1 << 3;
faces[2] = (1 << 0) | (1 << 6);
faces[3] = (1 << 0) | (1 << 3) | (1 << 6);
faces[4] = (1 << 0) | (1 << 1) | (1 << 5) | (1 << 6);
faces[5] = faces[4] | (1 << 3);
faces[6] = faces[4] | (1 << 2) | (1 << 4);
randomSeed(analogRead(A0));
show(6);
}
void loop() {
if (digitalRead(12) == HIGH) return;
int n = 1;
for (int d = 30; d < 300; d += d / 5 + 5) { // roll, slowing down
n = random(1, 7); show(n); delay(d);
}
while (digitalRead(12) == LOW) {}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Power up | Shows six |
| Button press | About a second of rolling, then one face from 1 to 6 |
| 60 rolls tallied | Each face between about 5 and 15 times |
If it does not work
A face looks wrong
Two LEDs are swapped. Match each pin to its dot position.
Always the same first roll
Leave A0 unconnected for the random seed.
One dot never lights
Turn the LED round or check its resistor.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the electronic dice with seven LEDs?
Arduino Nano, LED 5 mm red × 7, Resistor 330 Ω × 7, Tactile push button 6 mm, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the electronic dice with seven LEDs take to build?
About 45 minutes for a beginner maker, in 5 steps.
How do I know the electronic dice with seven LEDs works?
Power up: Shows six. Button press: About a second of rolling, then one face from 1 to 6. 60 rolls tallied: Each face between about 5 and 15 times.
A face looks wrong: what should I check?
Two LEDs are swapped. Match each pin to its dot position.
Always the same first roll: what should I check?
Leave A0 unconnected for the random seed.
One dot never lights: what should I check?
Turn the LED round or check its resistor.
