Arduino LED Dice Roller

Introduction: Arduino LED Dice Roller

About: Circuit E or Circuit E Makes is a series of media pages created to showcase various Electronics and Electrical Engineering projects. The goal of Circuit E is to inspire others to unleash their creativity and t…

This dice roller is a lot of fun and refreshes every 5 seconds.

Step 1: Place 7 LED's

It's best to make the LED's fit the pattern so it will look like a real die in the end. PAY ATTENTION TO THE POLARITIES!!!

Step 2: Connect Each LED to GND Through a 220 Ohm Resistor

Pay close attention to polarities.

Step 3: Add the Arduino to the Circuit and Connect the LED's

You can use any version of Arduino; this example used the Uno R3.

LED 1 - Digital Pin 2

LED 2 - Digital Pin 3

LED 3 - Digital Pin 4

LED 4 - Digital Pin 5

LED 5 - Digital Pin 6

LED 6 - Digital Pin 7

LED 7 - Digital Pin 8

DON'T FORGET TO CONNECT THE ARDUINO GND

Step 4: Push the Following Code to the Arduino

int led1 = 2;

int led2 = 3;

int led3 = 4;

int led4 = 5;

int led5 = 6;

int led6 = 7;

int led7 = 8;

void setup() {

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

pinMode(led5, OUTPUT);

pinMode(led6, OUTPUT);

pinMode(led7, OUTPUT);

Serial.begin(9600);

}

void loop(){

long randomnumber;

randomnumber = random(0, 7);

randomnumber;

if(randomnumber == 1){

Serial.println("1");

one();

}

if(randomnumber == 2){

Serial.println("2");

two();

}

if(randomnumber == 3){

Serial.println("3");

three();

}

if(randomnumber == 4){

Serial.println("4");

four();

}

if(randomnumber == 5){

Serial.println("5");

five();

}

if(randomnumber == 6){

Serial.println("6");

six();

}

}

void one(){

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

digitalWrite(led5, LOW);

digitalWrite(led6, LOW);

digitalWrite(led7, LOW);

again();

}

void two(){

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

digitalWrite(led5, LOW);

digitalWrite(led6, LOW);

digitalWrite(led7, HIGH);

again();

}

void three(){

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

digitalWrite(led5, LOW);

digitalWrite(led6, LOW);

digitalWrite(led7, HIGH);

again();

}

void four(){

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, LOW);

digitalWrite(led5, HIGH);

digitalWrite(led6, LOW);

digitalWrite(led7, HIGH);

again();

}

void five(){

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, LOW);

digitalWrite(led7, HIGH);

again();

}

void six(){

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, LOW);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

again();

}

void again(){

while(1){

delay(5000);

loop();

}

}

Attachments

Step 5: Test Your Dice Roller!

Be the First to Share

    Recommendations

    • Robots Contest

      Robots Contest
    • Halloween Contest

      Halloween Contest
    • Organization Contest

      Organization Contest

    Comments

    0
    Elaina M
    Elaina M

    1 year ago

    Thanks for sharing !