Digital Dice using Arduino

Tinkercad Lesson Notes - Class VII

Objective

What is a Digital Dice?

A Digital Dice is an electronic version of a traditional dice. Instead of rolling a cube, an Arduino generates a random number from 1 to 6 and displays the result using LEDs.

Concepts Covered

Components Required

Circuit Connections

Component Arduino Pin
LED 1D2
LED 2D3
LED 3D4
LED 4D5
LED 5D6
LED 6D7
Push ButtonD8 and GND

Each LED must be connected through a 220 Ω resistor to prevent damage from excessive current.

Working Principle

  1. Arduino waits for the push button to be pressed.
  2. When pressed, Arduino generates a random number between 1 and 6.
  3. The corresponding LED lights up.
  4. The LED remains ON briefly before the next roll.

Arduino Program

int leds[] = {2,3,4,5,6,7};
int button = 8;

void setup()
{
  for(int i=0;i<6;i++)
    pinMode(leds[i], OUTPUT);

  pinMode(button, INPUT_PULLUP);

  randomSeed(analogRead(A0));
}

void loop()
{
  if(digitalRead(button)==LOW)
  {
    int dice = random(1,7);

    for(int i=0;i<6;i++)
      digitalWrite(leds[i], LOW);

    digitalWrite(leds[dice-1], HIGH);

    delay(1000);
  }
}

How the Code Works

Class Activity

  1. Build the circuit in Tinkercad.
  2. Upload the Arduino code.
  3. Start the simulation.
  4. Press the push button several times.
  5. Observe the random LED output.

Challenge Activities

Real-Life Applications

Learning Outcomes

Quick Revision

Homework

  1. Modify the program so that all LEDs blink three times before displaying the final result.
  2. Replace the LEDs with a 7-segment display.
  3. Explain why resistors are necessary when connecting LEDs to Arduino.
⬅ Back to Robotics Club