Electronic dice using Arduino project

 In this project we will learn how to make electronic dice with seven segment display using Arduino. I'm sure you know something about the game Dice and its apps. Basically, it is in the shape of a cube with dots printed on each face. The dots represent the numbers one through six. In this project we are making electronic dice that perform the same task as real dice. Arduino is a microcontroller that runs on an ATmega 328p IC. There are many types of Arduino board available in the market but we are using Arduino UNO for this project. We also use a seven-part display to show numbers. You can also check out how the seven-part display works with the Arduino. You have to press the button so that the dice values ​​can be shuffled randomly and the final value is displayed soon. Make the circuit according to the given diagram and then upload the code provided.


We use a seven-segment unit of display that gives the number between one and six. To get a number on the dice you have to roll and roll but in this project you have to press the button until the numbers on the display start shuffling then give the final number. Once we get the final random number, the buzzer starts beeping. You can see the mixing of numbers on the seven-segment screen. Segment Seven is an electronic display device that can display numbers between zero to nine as well as all alphabets. It was named so because of the seven syllables used in it. This electronic dice gives numbers from one to six in a random way like real dice.

code arduino


// 7 Segment Common Anode #define aPin 7 // #define bPin 6 // _____ #define cPin 3 // | A | #define dPin 4 // F |_____| B #define ePin 5 // | G | #define fPin 8 // E |_____| C #define gPin 9 // D O dot // Pin configuration #define PIN_BUTTON A0 #define PIN_BUZZER 10 const byte PIN_CHAOS = A5; // Unconnected analog pin used to initialize RNG // Other configuration const unsigned int BEEP_FREQUENCY = 3000; int On=1; //<On=0; for Common anode><On=1; for Common cathode> int Off; void setup() { randomSeed(analogRead(PIN_CHAOS)); pinMode(aPin, OUTPUT); pinMode(bPin, OUTPUT); pinMode(cPin, OUTPUT); pinMode(dPin, OUTPUT); pinMode(ePin, OUTPUT); pinMode(fPin, OUTPUT); pinMode(gPin, OUTPUT); pinMode(PIN_BUTTON, INPUT_PULLUP); // On button pin as input with pullup pinMode(PIN_BUZZER, OUTPUT); // On buzzer pin as output // Indicate that system is ready for (int i = 9; i >=0; i--) { showNumber(i); tone(PIN_BUZZER, BEEP_FREQUENCY, 100); delay(300); } tone(PIN_BUZZER, BEEP_FREQUENCY, 250); // Beep when done delay(1000); // Wait for 1 second } void loop() { // Wait for button to be pressed, then run the test routine int buttonState = digitalRead(PIN_BUTTON); if (buttonState == LOW) { rollTheDice(10,100); // Show the rolling animation rollTheDice(5, 200); rollTheDice(3, 300); rollTheDice(1, 100); tone(PIN_BUZZER, BEEP_FREQUENCY, 250); // Beep when done } } void rollTheDice(int count, int delayLength) { for (int i = 0; i < count; i++) { int number = random(1,7); // Get random number from 1 to 6 tone(PIN_BUZZER, BEEP_FREQUENCY, 5); // Beep very shortly ("click") showNumber(number); // Show the number delay(delayLength); // Wait } } void showNumber(int x){ if(On==1){Off=0;} else{Off=1;} switch(x){ case 1: one(); break; case 2: two(); break; case 3: three(); break; case 4: four(); break; case 5: five(); break; case 6: six(); break; case 7: seven(); break; case 8: eight(); break; case 9: nine(); break; default: zero(); break; } } void one() { digitalWrite( aPin, On); // digitalWrite( bPin, Off); // | digitalWrite( cPin, Off); // | digitalWrite( dPin, On); // | digitalWrite( ePin, On); // | digitalWrite( fPin, On); digitalWrite( gPin, On); } void two(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, Off); // | digitalWrite( cPin, On); // ____| digitalWrite( dPin, Off); // | digitalWrite( ePin, Off); // |____ digitalWrite( fPin, On); digitalWrite( gPin, Off); } void three(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, Off); // | digitalWrite( cPin, Off); // ____| digitalWrite( dPin, Off); // | digitalWrite( ePin, On); // ____| digitalWrite( fPin, On); digitalWrite( gPin, Off); } void four(){ digitalWrite( aPin, On); // digitalWrite( bPin, Off); // | | digitalWrite( cPin, Off); // |____| digitalWrite( dPin, On); // | digitalWrite( ePin, On); // | digitalWrite( fPin, Off); digitalWrite( gPin, Off); } void five(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, On); // | digitalWrite( cPin, Off); // |____ digitalWrite( dPin, Off); // | digitalWrite( ePin, On); // ____| digitalWrite( fPin, Off); digitalWrite( gPin, Off); } void six(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, On); // | digitalWrite( cPin, Off); // |____ digitalWrite( dPin, Off); // | | digitalWrite( ePin, Off); // |____| digitalWrite( fPin, Off); digitalWrite( gPin, Off); } void seven(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, Off); // | digitalWrite( cPin, Off); // | digitalWrite( dPin, On); // | digitalWrite( ePin, On); // | digitalWrite( fPin, On); digitalWrite( gPin, On); } void eight(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, Off); // | | digitalWrite( cPin, Off); // |____| digitalWrite( dPin, Off); // | | digitalWrite( ePin, Off); // |____| digitalWrite( fPin, Off); digitalWrite( gPin, Off); } void nine(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, Off); // | | digitalWrite( cPin, Off); // |____| digitalWrite( dPin, Off); // | digitalWrite( ePin, On); // ____| digitalWrite( fPin, Off); digitalWrite( gPin, Off); } void zero(){ digitalWrite( aPin, Off); // ____ digitalWrite( bPin, Off); // | | digitalWrite( cPin, Off); // | | digitalWrite( dPin, Off); // | | digitalWrite( ePin, Off); // |____| digitalWrite( fPin, Off); digitalWrite( gPin, On); }


Post a Comment

Previous Post Next Post