LED Dice Using Arduino

Here you will find the tutorial to build a simple LED dice using arduino. The software build will be reliable and perfect enough to implement it in a real working environment. This project is very helpful in to build a basic arduino system.

Arduino technology is easy to use, efficient and reliable where it also allows dynamic and faster control. In this project we used random number generation technique. Every time you press the button, the LED’s roll for a while and glow a single LED.

led dice using arduino

Figure 1 show the circuit of LED dice using arduino. Talking about circuit component it uses arduino board, 7 LEDs and few passive components which are commonly available. In this project we uses 7-LED instead of six because of normal arrangement of a LED in the middle for odd-number roll. A single digital output is connected to single LED with single resistor, where this resistor is use as current limiting resistor.

PARTS LIST OF LED DICE USING ARDUINO

Resistor (all ¼-watt, ± 5% Carbon)
R1 = 100 KΩ

R2 – R8 = 270 Ω

Semiconductors
Arduino Diecimila or Uno or clone

LED1 – LED7 = 5-mm and color LED

Miscellaneous
SW1 = Push-to-on switch

 

The code for LED dice using arduino is very straight forward and there are a few nice touch to make it similar way to real dice. The array used in code determines which LEDs should be on or off for any particular throw.

THE CODE

int ledPins[7] = {2, 3, 4, 5, 6, 7, 8};

int dicePatterns[7][7] = {

{0, 0, 0, 0, 0, 0, 1}, // 1

{0, 0, 1, 1, 0, 0, 0}, // 2

{0, 0, 1, 1, 0, 0, 1}, // 3

{1, 0, 1, 1, 0, 1, 0}, // 4

{1, 0, 1, 1, 0, 1, 1}, // 5

{1, 1, 1, 1, 1, 1, 0}, // 6

{0, 0, 0, 0, 0, 0, 0} // BLANK

};

int switchPin = 9;

int blank = 6;

void setup()

{

for (int i = 0; i < 7; i++)

{

pinMode(ledPins[i], OUTPUT);

digitalWrite(ledPins[i], LOW);

}

randomSeed(analogRead(0));

}

void loop()

{

if (digitalRead(switchPin))

{

rollTheDice();

}

delay(100);

}

void rollTheDice()

{

int result = 0;

int lengthOfRoll = random(15, 25);

for (int i = 0; i < lengthOfRoll; i++)

{

result = random(0, 6); // result will be 0 to 5 not 1 to 6

show(result);

delay(50 + i * 10);

}

for (int j = 0; j < 3; j++)

{

show(blank);

delay(500);

show(result);

delay(500);

}

}

void show(int result)

{

for (int i = 0; i < 7; i++)

{

digitalWrite(ledPins[i], dicePatterns[result][i]);

}

}

Leave a Comment