## Introduction: Arduino Binary Dice

Are you playing ludo in this quarantine? If you are. I have created a binary dice for you. You just need an Arduino and a few components.

Maybe you have played ludo in this quarantine. I am almost sure that you use normal dice. Well, that is until today.

If you are a maker, I am pretty sure that the next time you play ludo you will use the binary dice that I present in this post.

You will only need an Arduino Uno and a few other components that I am sure you have.

It works is very simple. You only have to push the button and the LEDs show you the number. I use three LEDs to represent the number. If you do not know about binary, you only need to sum the number that appears below the LED or LEDs that are turned on.

## Step 1: Have a Hand All Components

It always is recommended to have a hand all components.

That will save you time.

## Step 2: Let's Connect Them

Make the connections indicates in the diagram.

After uploading the sketch to the Arduino. You can use the power supply adapter to energize the Arduino.

## Step 3: Upload the Code

// Binary Dice
// www.rjconcepcion.com

// Variable declaration
int const d1 = 2;
int const d2 = 4;
int const d3 = 6;
int const btn = 12;

// aleatory number variable
int number = 0;

void setup() {
Serial.begin(9600);

pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(btn, INPUT_PULLUP); // Set input with pullup resistor

randomSeed(analogRead(0)); // Inicialize random number generator

}

void loop() {

digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);

delay(20);

number = random(7);         // Generate a random number between 0 and 6.
}
}

// Switch case structure allows to take an action depends number value. Every case represent a binary number using leds.
switch (number) {
case 0:
break;

case 1:
digitalWrite(d1, HIGH);
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
delay(5000);
break;

case 2:
digitalWrite(d1, LOW);
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
delay(5000);
break;

case 3:
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
delay(5000);
break;

case 4:
digitalWrite(d1, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
delay(5000);
break;

case 5:
digitalWrite(d1, HIGH);
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
delay(5000);
break;

case 6:
digitalWrite(d1, LOW);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
delay(5000);
break;

default:
break;

}

number = 0;

delay(250);
digitalWrite(d1, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
delay(250);

}

## Step 4: Test and Let's Play Ludo

You can see the video for an explanation. The bad news is in Spanish.

I hope you enjoy this project. See you soon.