arduinobot12
Published

Easy Arduino Digital Dice

This project allows you to create a really simple digital dice using a one-digit seven segment display and a photoresistor.

BeginnerFull instructions provided1,202
Easy Arduino Digital Dice

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Photo resistor
Photo resistor
×1
7 Segment LED Display, Red
7 Segment LED Display, Red
Any color is fine
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×8
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

Code

Arduino
You can either copy+paste this code into an Arduino Sketch, or download it.
int a = 7;
int b = 6;
int c = 5;
int d = 11;
int e = 10;
int f = 8;
int g = 9;
int dp = 4;
int a = 7;
int b =    6;
int c = 5;
int d = 11;
int e = 10;
int f = 8;
int g = 9;
int start = 400;

void setup() {
  Serial.begin(9600);
  digitalWrite(a, OUTPUT);
  digitalWrite(b, OUTPUT);
  digitalWrite(c, OUTPUT);
  digitalWrite(d, OUTPUT);
  digitalWrite(e, OUTPUT);
  digitalWrite(f, OUTPUT);
  digitalWrite(g, OUTPUT);
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}


void loop() {
  int ran = random(1, 6);
  Serial.print(ran);
  int value = analogRead(A0);
  if (start < start && ran == 1)
  {
    digitalWrite(c, HIGH);
    digitalWrite(b, HIGH);
    delay(9000);
    digitalWrite(c, LOW);
    digitalWrite(b, LOW);
  }
  else if (value < start && ran == 2)
  {
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(g, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(d, HIGH);
    delay(9000);
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(g, LOW);
    digitalWrite(e, LOW);
    digitalWrite(d, LOW);
  }
  else if (value < start && ran == 3)
  {
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(g, HIGH);
    digitalWrite(c, HIGH);
    delay(9000);
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(g, LOW);
  }
  else if (value < start && ran == 4)
  {
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    delay(9000);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW); 
  }
  else if (value < start && ran == 5)
  {
    digitalWrite(a, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    delay(9000);
    digitalWrite(a, LOW);
    digitalWrite(f, LOW);         
    digitalWrite(g, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
  }
  else if (value < start && ran == 6)
  {
    digitalWrite(a, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    delay(9000);
    digitalWrite(a, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
  }
  delay(500);
}

Credits

arduinobot12

arduinobot12

0 projects • 1 follower

Comments