Introduction: Electronic Dice!!!

About: Hi!! I AM Lloyd lobo studying science in 12th class and i have a youtube channel (dynamic innovator)and i like to make stuffs!!! like arduino,random projects ,electronic projects , science,and some times scien…


I made a dice throwing prototype: if you press the button, a random number between 1 and 6 is generated and the corresponding number of LEDs are lit up. This was a holiday project with my kids :)

Dice throwing prototype using Arduino UNO, a button switch and 6 LEDs.

Full tutorial on my channel visit my channel for full tutorial!!!

Step 1: Parts & Materials Required!!!

  • Arduino uno
  • 6x LED'S
  • A breadbord or a prototyping board
  • 6x 220 ohm Resistors
  • 1x 1k ohm Resistors
  • A push button

Step 2: Circuit Diagram!!!

I have made a circuit diagram for the connections of Arduino,led,push button and resistors.

see the circuit diagram for the connections.

Step 3: Connections!!!

Now connect led's negative terminal to the 220ohm resistors and positive terminal to the arduino's digital pins from 2 to 7.and connect the other led of the resistors to the Gnd(ground) pin.

For rest of the connections for push button see the circuit diagram!!

Step 4: Additional Changes for the Led's!!!

I have added the BRIDGE like structure at the middle of the breadboard for the led's to rest infront of the wires and resistors JUST TO LOOK CLEAN.


Step 5: CODE!!

  //Now hook up your pc with arduino and just download the below code and upload to your arduino.
//Dynamic Innovator// set to 1 if we're debugging
#define DEBUG 0

// 6 consecutive digital pins for the LEDs
int first = 2;
int second = 3;
int third = 4;
int fourth = 5;
int fifth = 6;
int sixth = 7;

// pin for the button switch
int button = 12;
// value to check state of button switch
int pressed = 0;

void setup() {
  // set all LED pins to OUTPUT
  for (int i=first; i<=sixth; i++) {
    pinMode(i, OUTPUT);
  // set buttin pin to INPUT
  pinMode(button, INPUT);
  // initialize random seed by noise from analog pin 0 (should be unconnected)

  // if we're debugging, connect to serial 
  #ifdef DEBUG


void buildUpTension() {
  // light LEDs from left to right and back to build up tension
  // while waiting for the dice to be thrown
  // left to right
  for (int i=first; i<=sixth; i++) {
    if (i!=first) {
      digitalWrite(i-1, LOW);
    digitalWrite(i, HIGH);
  // right to left
  for (int i=sixth; i>=first; i--) {
    if (i!=sixth) {
      digitalWrite(i+1, LOW);
    digitalWrite(i, HIGH);

void showNumber(int number) {
  digitalWrite(first, HIGH);
  if (number >= 2) {
    digitalWrite(second, HIGH);
  if (number >= 3) {
    digitalWrite(third, HIGH);    
  if (number >= 4) {
    digitalWrite(fourth, HIGH);    
  if (number >= 5) {
    digitalWrite(fifth, HIGH);    
  if (number == 6) {
    digitalWrite(sixth, HIGH);    

int throwDice() {
  // get a random number in the range [1,6]
  int randNumber = random(1,7);
  #ifdef DEBUG
  return randNumber;

void setAllLEDs(int value) {
  for (int i=first; i<=sixth; i++) {
    digitalWrite(i, value);

void loop() {
  // if button is pressed - throw the dice
  pressed = digitalRead(button);

  if (pressed == HIGH) {
    // remove previous number
    int thrownNumber = throwDice();


Step 6: Electronic Dice Is Ready !!!

Just see the pictures above .. or visit my youtube channel for the tutorial and working!!!

Toys and Games Challenge

Participated in the
Toys and Games Challenge