DIY Arduino Based Electronic Dice

by Utsource in Circuits > Arduino

2041 Views, 3 Favorites, 0 Comments

DIY Arduino Based Electronic Dice

Screenshot_20191017-182106__01.jpg
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.

Things You Need

Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png
images(94).jpg

For this instructables we will be using following things :

Arduino UNO.


Seven segment display (Common Anode)
Push buttons

Connecting wires

Bread board
1 k resistor
Power supply

Connections

20191017_183046.jpg
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.

Code

images(85).jpg
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();
if(digitalRead(dice)==0)
{
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);
}

if(digitalRead(resett)==0)
{
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);
}
}
}

Playing With the Dice

Screenshot_20191017-182106__01.jpg
Screenshot_20191017-182114__01.jpg
Screenshot_20191017-182125__01.jpg
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.