## Introduction: DIY Arduino Based Electronic Dice

Hi guys as we all have played with a DICE as a kid and since we used dice in many games like snakes & ladders etc. So i thought why shouldn't we refresh ourself with a new concept of dice and that brings us to Arduino based Homemade digital/electronic DICE, which will randomly show the output number which will randomly generated by Arduino.

## Step 1: Things You Need

For this instructables we will be using following things :

Arduino UNO.

Seven segment display (Common Anode)
Push buttons

Connecting wires

1 k resistor
Power supply

## Step 2: Connections

IN this circuit, a common anode seven segment display is used for displaying dice numbers, which is directly connected to arduino digital pin numbers 6, 5, 4, 3, 2, 1, 0. And common anode pin of seven segment is connected with +5 volt 220 Ohm resistor. Two push button are also connected namely dice button and reset button which are connected to digital pin 14 (A0) and 15 (A1) with respect to ground. So connect everything According to all these details & shown schmatics.

## Step 3: Code

Copy the following code & upload it to your arduino Board :

#define resett 15
#define dice 14
char digit[6]={0x02, 0x79, 0x24, 0x30, 0x19, 0x12};
int pin[7]={6,5,4,3,2,1,0};
void setup()
{
for(int i=0;i<7;i++)
pinMode(pin[i], OUTPUT);
pinMode(dice, INPUT);
pinMode(resett, INPUT);
digitalWrite(dice, HIGH);
digitalWrite(resett, HIGH);
int temp=0x40;
for(int i=0;i<7;i++)
{
int temp1=temp&0x01;
digitalWrite(pin[i], temp1);
temp=temp>>1;
}
delay(1000);
}
void loop()
{
int temp=rand();
{
int k=temp%6;
temp=digit[k];
wait();
for(int i=0;i<7;i++)
{
int temp1=temp&0x01;
digitalWrite(pin[i], temp1);
temp=temp>>1;
}
delay(200);
}

{
temp=0x40;
for(int i=0;i<7;i++)
{
int temp1=temp&0x01;
digitalWrite(pin[i], temp1);
temp=temp>>1;
}
}
}
void wait()
{
for(int m=0;m<10;m++)
{
for(int k=0;k<6;k++)
{
int ch=digit[k];
for(int l=0;l<7;l++)
{
char tem2=ch&0x01;
digitalWrite(pin[l], tem2);
ch=ch>>1;
}
delay(50);
}
}
}

## Step 4: Playing With the Dice

So after connecting everything together & uploading code to Arduino board, plug the power & your DIY dice is ready to play with. So here two buttons are provided if you press one button it will randomly select a number and show it on 7-segment display and the other button can reset it. So have fun making your own electronic dice & have fun playing with it.