Arduino Electronic Dice

808

8

1

Materials needed:

  • 7 Led lights
  • push button
  • 10 wires
  • 8 resistors
  • breadboard
  • arduino uno

Supplies:

Step 1: LEDs

  • Get 7 led lights and construct them in an H pattern on the breadboard so their are 3 LEDs on each side and one in the middle.

Step 2: Resistors

  • Then connect a resistor from the negative side of each LED to the negative (-) slot.
  • Add a wire connecting the negative spot (-) to GND.

Step 3: Push Button

  • Put the push button bellow the lights and connect the bottom left leg to GND
  • Then add a wire to the top left leg and connect it to 5V in the arduino circuit board.
  • Add a 10k Ohm resistor to the bottom left leg of the push button

Step 4: Wiring

  • Add wires to to the positive end of each LED and connect it to a number slot on the arduino circuit board.

Step 5: Code

The code as of right now is:

int pinLeds1 = 10;

int pinLeds2 = 9;

int pinLeds3 = 8;

int pinLed4 = 7;

int buttonPin = 6;

int buttonState;

long ran;

int time = 2000;

void setup (){ pinMode (pinLeds1, OUTPUT);

pinMode (pinLeds2, OUTPUT);

pinMode (pinLeds3, OUTPUT);

pinMode (pinLed4, OUTPUT);

pinMode (buttonPin, INPUT);

randomSeed(analogRead(0));

}

void loop(){ buttonState = digitalRead(buttonPin);

if (buttonState == HIGH){ ran = random(1, 7);

if (ran == 1){ digitalWrite (pinLed4, HIGH);

delay (time);

}

if (ran == 2){ digitalWrite (pinLeds1, HIGH);

delay (time);

}

if (ran == 3){ digitalWrite (pinLeds3, HIGH);

digitalWrite (pinLed4, HIGH);

delay (time);

}

if (ran == 4){ digitalWrite (pinLeds1, HIGH);

digitalWrite (pinLeds3, HIGH);

delay (time);

}

if (ran == 5){ digitalWrite (pinLeds1, HIGH);

digitalWrite (pinLeds3, HIGH);

digitalWrite (pinLed4, HIGH);

delay (time);

}

if (ran == 6){ digitalWrite (pinLeds1, HIGH);

digitalWrite (pinLeds2, HIGH);

digitalWrite (pinLeds3, HIGH);

delay (time);

}

}

digitalWrite (pinLeds1, LOW);

digitalWrite (pinLeds2, LOW);

digitalWrite (pinLeds3, LOW);

digitalWrite (pinLed4, LOW);

}

Step 6: Test Your Work

  • Upload the code onto the arduino circuit board and test whether or not your masterpiece works.

We ran into some minor problems. When pressing the button once, the LEDs would flash multiple random numbers. While the dice still works there are improvements that could be made.

Share

    Recommendations

    • Woodworking Contest

      Woodworking Contest
    • Gardening Contest

      Gardening Contest
    • Arduino Contest 2019

      Arduino Contest 2019

    Discussions