Day 01

Begineer

Day 17 :- Electronic Dice

Aug 23, 2026

Completed

Wiring Schematic

Arduino Code

ARDUINO / C++

Day 17 Core Training Documentation

Project Overview

The Electronic Dice project teaches you how to use random number generation to create an interactive game device: a digital dice that rolls and displays random numbers.

In this project, Arduino generates random numbers from 1 to 6 and displays the result on a 7-segment display. When a button is pressed, the dice “rolls” by rapidly cycling through all numbers, then lands on a random result.

When the user presses the button, the 7-segment display shows numbers changing rapidly in a dice-rolling animation. After a short period, the display lands on a random number from 1 to 6, simulating a real physical dice roll.

This project teaches Random Number Generation, Button Input Processing, Display Animation Techniques, Game Logic Programming, and Interactive User Experiences.

By finishing this project, you’ll understand how game systems work and how randomization creates engaging interactive applications in both games and simulations.

Components Required

To build this circuit, collect these specific items from your kit:

Arduino Uno × 1, Breadboard × 1, 7-Segment Display (Common Cathode) × 1, 220Ω Resistor × 7, Push Button × 1, 10kΩ Resistor × 1, Jumper Wires × 10, USB Cable × 1

Circuit Connections

Step 1: Connect Ground Rail

Connect the Arduino GND pin to the negative rail of the breadboard. This creates a shared ground connection for all components.

Step 2: Insert 7-Segment Display

Place the 7-segment display into the breadboard with proper orientation. Ensure all pins are inserted into separate breadboard rows for reliable connections.

Step 3: Connect Display Common Cathode

Connect both common cathode pins (middle pins) of the 7-segment display to the breadboard GND rail. This provides ground to all LED segments.

Step 4: Connect Display Segments A through G

Connect segment A to Arduino Pin 2 through a 220Ω resistor. Connect segment B to Pin 3 through a resistor. Connect segment C to Pin 4, segment D to Pin 5, segment E to Pin 6, segment F to Pin 8, and segment G to Pin 9, each through their own 220Ω resistor.

Step 5: Connect Push Button

Place the push button on the breadboard across the center gap. Connect one side of the button to Arduino Pin 7. Connect the other side to the breadboard GND rail.

Step 6: Connect Pull-Up Resistor

Connect the 10kΩ pull-up resistor between Arduino Pin 7 and Arduino 5V. This ensures the pin reads HIGH when the button is not pressed.

Step 7: Verify All Connections

Check all segment resistors and button connections before uploading your code. Ensure each segment connects through a protective resistor to the correct pin.

Important: Each segment requires its own 220Ω resistor. The pull-up resistor on the button is essential for reliable button press detection.

How the Arduino Code Works

Configure Pins and Initialize

In setup(), Arduino sets all segment pins as OUTPUT. Pin 7 (button) is set as INPUT_PULLUP. The random seed is initialized using analogRead() on an unconnected pin to ensure truly random number generation.

Create Segment Patterns

Arrays store the segment patterns for numbers 1 through 6. Each pattern specifies which segments illuminate to display the corresponding number on the 7-segment display.

Read Button Input

The program continuously checks if the button is pressed using digitalRead(). When the button transitions from HIGH to LOW, a dice roll begins.

Animate Dice Roll

When rolling, the program rapidly cycles through numbers 1 to 6 multiple times. Each number displays for a short duration, creating the visual effect of a dice rolling.
 

Display Random Result

After the animation completes, a random number from 1 to 6 is generated using random(). This number displays on the 7-segment display until the user presses the button again to roll again.

Expected Output

After uploading your code, here is what happens.

At startup, the 7-segment display shows the number 1. Press the button and the display begins rapidly showing numbers 1 through 6 in sequence repeatedly. The cycling accelerates creating a rolling animation effect. After approximately 1 to 2 seconds, the animation slows and stops on a random number from 1 to 6. This number remains displayed until you press the button again to roll the dice again.

Operational Troubleshooting

Display Does Not Show Numbers :- Check that all seven segment resistors are properly connected. Verify that the common cathode pins connect to ground. Check that each segment pin connects to the correct Arduino pin.

Button Press Does Not Roll Dice :- Verify the button connects to Pin 7 and that the pull-up resistor is between Pin 7 and 5V. Check your button press detection logic to ensure it correctly identifies the button state change..

Dice Always Shows Same Number :- Ensure the random seed initialization is included in setup(). Verify that the random() function is being called with the correct range of 1 to 6.

Dice Roll Animation Too Fast :- Increase the delay value in the animation loop. Longer delays make the rolling effect slower and easier to watch. Experiment with delay times between 50 and 200 milliseconds.

Some Segments Do Not Light :- Check the resistor values and connections. Verify that each segment connects to the correct pin through its own resistor without shared connections.

What You Learned

By finishing this project, you now know :-

How to generate random numbers using Arduino, how to detect button press events, how to create animated display effects, how to store and retrieve display patterns, and how to build interactive gaming applications.

Next Lesson

In Day 18, you’ll learn how to use an OLED display to show real-time information and graphics, creating a professional information display system for advanced monitoring applications.