Skip to main content

Electronic Dice Using Arduino


Introduction 

Dice is used to play many games like snake ladder, Ludo etc. Generally dice is made up of wooden or plastic, which gets deformed with time and become biased. A Digital dice is a good alternative of old fashioned dice, it can’t be biased or deformed. It operates at such high speed that no one can cheat. To create this digital dice circuit, we have mainly used Arduino Uno, Pushbutton switch and 6 led along with 220ohm resistors.


Code for the project:-



// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin

// Variables will change:
int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH),  and you've waited
  // long enough since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        int num=random(1,7);
        if(num==1)
        {
          digitalWrite(13,HIGH);
          digitalWrite(12,LOW);
          digitalWrite(11,LOW);
          digitalWrite(10,LOW);
          digitalWrite(9,LOW);
          digitalWrite(8,LOW);
          delay(2000);
        }
        else if(num==2)
        {
          digitalWrite(13,HIGH);
          digitalWrite(12,HIGH);
          digitalWrite(11,LOW);
          digitalWrite(10,LOW);
          digitalWrite(9,LOW);
          digitalWrite(8,LOW);
          delay(2000);
        }
        else if(num==3)
        {
          digitalWrite(13,HIGH);
          digitalWrite(12,HIGH);
          digitalWrite(11,HIGH);
          digitalWrite(10,LOW);
          digitalWrite(9,LOW);
          digitalWrite(8,LOW);
          delay(2000);
        }
        else if(num==4)
        {
          digitalWrite(13,HIGH);
          digitalWrite(12,HIGH);
          digitalWrite(11,HIGH);
          digitalWrite(10,HIGH);
          digitalWrite(9,LOW);
          digitalWrite(8,LOW);
          delay(2000);
        }
        else if(num==5)
        {
          digitalWrite(13,HIGH);
          digitalWrite(12,HIGH);
          digitalWrite(11,HIGH);
          digitalWrite(10,HIGH);
          digitalWrite(9,HIGH);
          digitalWrite(8,LOW);
          delay(2000);
        }
        else if(num==6)
        {
          digitalWrite(13,HIGH);
          digitalWrite(12,HIGH);
          digitalWrite(11,HIGH);
          digitalWrite(10,HIGH);
          digitalWrite(9,HIGH);
          digitalWrite(8,HIGH);
          delay(2000);
        }
      }
    }
  }

 // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonState = reading;
          digitalWrite(13,LOW);
          digitalWrite(12,LOW);
          digitalWrite(11,LOW);
          digitalWrite(10,LOW);
          digitalWrite(9,LOW);
          digitalWrite(8,LOW);

}




Connections for switch :-

Image result for arduino debounce
Connect 6 leds to digital pin 13,12,11,10,9,8 respectively with resistors.

Comments

Popular posts from this blog

Lock using 4 Push button switch with arduino

Introduction : A  combination lock  is a type of locking device in which a  sequence  of symbols, usually numbers, is used to open the lock. The sequence may be entered using a single rotating dial which interacts with several discs or  cams , by using a set of several rotating discs with inscribed symbols which directly interact with the locking mechanism, or through an electronic or mechanical keypad. Here we will be using arduino uno along with em lock to make door lock with password.  Code of the project :- const int buttonPin1 = 1; const int buttonPin4 = 4; const int buttonPin3 = 3; const int buttonPin2 = 2; // the pin that the pushbutton is attached to const int correctLedPin = 7;       // the pin that the LED is attached to const int wrongLedPin = 6;  const int motorPin = 11;// the pin that the LED is attached to // variables that are changed by the program int buttonPushCounter = 0;   // co...

Voice Recording Module ISD1820 with Arduino

1 Introduction  Voice Record Module is base on ISD1820, which a multiple‐message record/playback device. It can offers true single‐chip voice recording, no‐volatile storage, and playback capability for 8 to 20 seconds. The sample is 3.2k and the total 20s for the Recorder. This module use is very easy which you could direct control by push button on board or by Microcontroller such as Arduino, STM32, ChipKit etc. Frome these, you can easy control record , playback and repeat and so on. 2 Feature  - Push‐button interface, playback can be edge or level activated - Automatic power‐dwon mode - On‐chip 8Ω speaker driver - Signal 3V Power Supply - Can be controlled both manually or by MCU - Sample rate and duration changable by replacing a single resistor - Record up to 20 seconds of audio - Dimensions: 37 x 54 mm If you want change record duration, an external resistor is necessary to select the record duration and sampling frequency, which can range from ...

Home Automation Using Arduino (Relay Module)

Inroduction to Home Automation Home automation  or  domotics  is  building automation  for a home, called a  smart home  or  smart house . It involves the control and automation of lighting, heating (such as  smart thermostats ), ventilation, air conditioning ( HVAC ), and security, as well as  home appliances  such as washer/dryers, ovens or refrigerators/freezers.  Wi-Fi  is often used for remote monitoring and control. Home devices, when remotely monitored and controlled via the Internet, are an important constituent of the  Internet of Things . Modern systems generally consist of switches and sensors connected to a central hub sometimes called a "gateway" from which the system is controlled with a  user interface that is interacted either with a wall-mounted terminal, mobile phone software,  tablet computer  or a web interface, often but not always via Internet cloud services.     ...