Introduction: Arduino Led Dice

This instructable will show you how to create a dice using Arduino and few components. It's an easy and fun project, suitable for beginners and those who want to start with Arduino; it also requires a minimal amount of components.
This explaines how to create it in the breadboard, how to solder it and how to make some changes.

Step 1: What Is Arduino?

Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It's an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board.

Arduino can be used to develop interactive objects, taking inputs from a variety of switches or sensors, and controlling a variety of lights, motors, and other physical outputs. Arduino projects can be stand-alone, or they can be communicate with software running on your computer (e.g. Flash, Processing, MaxMSP.) The boards can be assembled by hand or purchased preassembled; the open-source IDE can be downloaded for free.

The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment.

Why Arduino?

There are many other microcontrollers and microcontroller platforms available for physical computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handyboard, and many others offer similar functionality. All of these tools take the messy details of microcontroller programming and wrap it up in an easy-to-use package. Arduino also simplifies the process of working with microcontrollers, but it offers some advantage for teachers, students, and interested amateurs over other systems:

  • Inexpensive - Arduino boards are relatively inexpensive compared to other microcontroller platforms. The least expensive version of the Arduino module can be assembled by hand, and even the pre-assembled Arduino modules cost less than $50
  • Cross-platform - The Arduino software runs on Windows, Macintosh OSX, and Linux operating systems. Most microcontroller systems are limited to Windows.
  • Simple, clear programming environment - The Arduino programming environment is easy-to-use for beginners, yet flexible enough for advanced users to take advantage of as well. For teachers, it's conveniently based on the Processing programming environment, so students learning to program in that environment will be familiar with the look and feel of Arduino
  • Open source and extensible software- The Arduino software and is published as open source tools, available for extension by experienced programmers. The language can be expanded through C++ libraries, and people wanting to understand the technical details can make the leap from Arduino to the AVR C programming language on which it's based. SImilarly, you can add AVR-C code directly into your Arduino programs if you want to.
  • Open source and extensible hardware - The Arduino is based on Atmel's ATMEGA8 and ATMEGA168 microcontrollers. The plans for the modules are published under a Creative Commons license, so experienced circuit designers can make their own version of the module, extending it and improving it. Even relatively inexperienced users can build the breadboard version of the module in order to understand how it works and save money.

How do I use Arduino?

Step-by-step instructions for setting up the Arduino software and connecting it to an Arduino Duemilanove:

(All this part was taken from the official website of Arduino)

Step 2: Parts & Tools

This is what you need for this simple project:

Parts:
  • Arduino
  • 7x Leds of any kind (I use 5mm Red Leds)
  • A 10k Resistor (brown black orange)
  • 7x 220 or 330 Resistor (red red brown or orange orange brown)
  • A little Push Button
  • Breadboard
  • Some wires for the breadboard
Tools:
  • The arduino programmer (you can download it from the official site of Arduino)
  • Usb Cable A-B
  • Soldering Iron (If you want solder the project)
  • A ProtoBoard (f you want solder the project)
  • Solder Spool (If you want solder the project)
  • Third Hand (optional, but useful if you want solder the project)

Step 3: Schematic & Intro

To create all the six faces of a dice, you need 7 LEDs, placed in the shape of an "H".
As you can see from the diagram, they're not all linked to different pins of Arduino, but most are connected in pairs, to facilitate the use.
To create all the faces of the dice, you must follow these rules:
For the number 1 of the dice: lights up the led 4
For the number 2 of the dice: lights up the group 1
For the number 3 of the dice: lights up the groups 3 and 4
For the number 4 of the dice: lights up the groups 1 and 3
For the number 5 of the dice: lights up the groups 1, 3 and 4
For the number 6 of the dice: lights up the groups 1, 2 and 3

If you want to see the schematic with more detail, click here:
https://www.instructables.com/files/orig/F5L/A4E0/G1BB7YY2/F5LA4E0G1BB7YY2.jpg

Step 4: Place the Components on the Breadboard

First, place the Leds in the shape of an "H". It may be a little difficult to find the right configuration without superimpose the leds, but in the pictures there is a scheme to facilitate this part.
After that, connect all the cathodes of the Leds to ground with 220 or 330 ohm resistors  (red red brown or orange orange brown)
Then, put the pushbutton on the breadboard and connect it to ground with 10k ohm resistance.

Step 5: Connect the Components With Arduino

Now....let's take Arduino!
First, attach the Arduino ground with the ground line of the breadboard
Then, connect the Leds to Arduino...this part can be a bit difficult, but there is an useful schematic.
Finally, connect the 5v of arduino with the button, and connect the button with the pin 6 of Arduino...be careful also in this part and follow the picture.

Hey...you're done!

Step 6: Program Code

This is the code without the comments to reduce the space (You can find the comments in the downloadable file):

int pinLeds1 = 10;
int pinLeds2 = 9;
int pinLeds3 = 7;
int pinLed4 = 8;
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 7: Test It!

Now the Arduino led dice is finished and you can try it...you just have to power Arduino and press the button to see the number!
This project is very useful for those who wants to begin to become familiar with Arduino, the code is easy, clean and funny.
Now, if you want to improve the project, you can try to solder it or make some changes, as explained in the next steps of instructable.

Step 8: Solder the Arduino Led Dice

If you want, you can also solder the project, to make it more compact and better.
Solder is not easy, and if you are a beginner, I recommend to follow some guides on the web to learn it.
In the images, there's my old solder version of my Arduino led dice, and unfortunately, in this version each led is connected to an Arduino pin: during soldering, it's advisable to connect the LEDs in pairs as in the breadboard version, for convenience.

Step 9: Project Variations

You can also apply funny changes to the project, such as using a tilt switch or a vibrator switch instead of the button. So, to read the number of the dice just shake the breadboard, and it's funny!
If you want to do this, simply connect the tilt switch to the 5V Arduino and the other side to pin 6 of Arduino, as in figure.

For the tilt switch, you need to change this line code:
if (buttonState == HIGH) {
in this:
if (buttonState == LOW) {
Now you just have to take the project in hand, shake it (without breaking it!) and read the number!

Comments

author
AqmerA (author)2016-12-11

it was not working i made it two times can you help me

author
Rishabhm8 made it! (author)2016-10-01

Easy!!!

WP_20161001_005.jpg
author

Sir can i copy ur code plssss need lang or ask ko n lng tama mo ba ung code na nksave d2. Thank you.

author
Rishabhm8 made it! (author)2016-10-01

Easy and creative.

WP_20161001_005.jpg
author
R Jordan Kreindler (author)2016-07-11

Nice Instructable. Thanks for sharing.

author
nseixas made it! (author)2016-05-01

Great project to start with Arduino.

I did some changes to the code.

Code at: https://github.com/NelsonSeixas/Arduino.git

20160501_130630.jpg
author
lionn (author)2016-02-04

Thank you sooo much for this good informations and this amazing website

author
Dr Snick (author)2016-01-16

Thanks for the Great Tutorial!

I made a Arduino Dice Game 10.000 very cool

https://www.youtube.com/watch?v=FM2D7WqH6cY

author
JayP6 made it! (author)2015-12-27

Got my arduino for Christmas, and I love it! This is a good simple project for a new arduino user, especially since all the parts are included in the starter kit. Great instructable, thanks!

LEDdice6.jpgLEDdice5.jpgLEDdice4.jpgLEDdice3.jpgLEDdice2.jpgLEDdice1.jpg
author
IvanG55 made it! (author)2015-12-25

Thank you

IMG_0740.jpg
author
IvanG55 made it! (author)2015-12-25

This was my first arduino project. Thanks for the great instructions

IMG_0741.MOVIMG_0740.jpg
author
IvanG55 made it! (author)2015-12-25

This was my first arduino project. Thanks for the great instructions

IMG_0741.MOVIMG_0740.jpg
author
IvanG55 made it! (author)2015-12-25

This was my first arduino project. Thanks for the great instructions

IMG_0741.MOVIMG_0740.jpg
author
IvanG55 made it! (author)2015-12-25

Awesome.. Was my first project.. Thank you for the great instuctions and schematic.

IMG_0740.jpgIMG_0741.MOV
author
IvanG55 made it! (author)2015-12-25

Awesome.. Was my first project.. Thank you for the great instuctions and schematic.

IMG_0740.jpgIMG_0741.MOV
author
IvanG55 made it! (author)2015-12-25

Awesome.. Was my first project.. Thank you for the great instuctions and schematic.

IMG_0740.jpgIMG_0741.MOV
author
KevinS142 made it! (author)2015-12-18

Works like a charm!!!!

Led dice.JPG
author
Muhammad Irfan Bajwa (author)2015-11-28

/*Here is the Code for Dice with 7-SEGMENT Display as well as Led's will glow up acording to Dice Random Number

Simulation Software is Proteus*/

int led[]={38,39,40,41,42,43};

int a=22,b=23,c=24,d=25,er=26,f=27,g=28,buttonpin=32 ;

void setup() {

// put your setup code here, to run once:

//pinMode(led1,OUTPUT);

pinMode(a,OUTPUT);

pinMode(b,OUTPUT);

pinMode(c,OUTPUT);

pinMode(d,OUTPUT);

pinMode(er,OUTPUT);

pinMode(f,OUTPUT);

pinMode(g,OUTPUT);

pinMode(buttonpin,INPUT);

for(int i=0;i<=5;i++)

{

pinMode(led[i],OUTPUT);

}

}

void loop() {

int x,y,j;

// put your main code here, to run repeatedly:

Back:

y=digitalRead(buttonpin);

if(y==0)

{

goto Back;

}

x=random(7);

if(y==1 && x==1)

{

goto Dice_1;

}

else if(y==1 && x==2)

{

goto Dice_2;

}

else if(y==1 && x==3)

{

goto Dice_3;

}

else if(y==1 && x==4)

{

goto Dice_4;

}

else if(y==1 && x==5)

{

goto Dice_5;

}

else if(y==1 && x==6)

{

goto Dice_6;

}

else

{

goto Back;

}

Dice_1:

{

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(a,LOW);

digitalWrite(d,LOW);

digitalWrite(er,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

digitalWrite(led[0],HIGH);

delay(1000);

digitalWrite(led[0],LOW);

delay(500);

goto Back;

}

//goto Back;

Dice_2:

{

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(a,HIGH);

digitalWrite(d,HIGH);

digitalWrite(er,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,HIGH);

digitalWrite(led[0],HIGH);

digitalWrite(led[1],HIGH);

delay(1000);

digitalWrite(led[0],LOW);

digitalWrite(led[1],LOW);

delay(500);

goto Back;

}

Dice_3:

{

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(a,HIGH);

digitalWrite(d,HIGH);

digitalWrite(er,LOW);

digitalWrite(f,LOW);

digitalWrite(g,HIGH);

for(j=0;j<=2;j++)

{

pinMode(led[j],HIGH);

}

delay(1000);

for(j=0;j<=2;j++)

{

pinMode(led[j],LOW);

}

delay(500);

goto Back;}

Dice_4:

{

digitalWrite(a,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,LOW);

digitalWrite(er,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

for(j=0;j<=3;j++)

{

digitalWrite(led[j],HIGH);

}

delay(1000);

for(j=0;j<=3;j++)

{

digitalWrite(led[j],LOW);

}

delay(500);

goto Back;

}

Dice_5:

{

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(er,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

for(j=0;j<=4;j++)

{

digitalWrite(led[j],HIGH);

}

delay(1000);

for(j=0;j<=4;j++)

{

digitalWrite(led[j],LOW);

}

delay(500);

goto Back;

}

Dice_6:

{

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(er,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

for(j=0;j<=5;j++)

{

digitalWrite(led[j],HIGH);

}

delay(1000);

for(j=0;j<=5;j++)

{

digitalWrite(led[j],LOW);

}

delay(500);

goto Back;

}

}

author
NicolasM29 made it! (author)2015-10-20

Arduino Project Review

Review:

This
circuit was easy however we had a lot of trouble finding a good push button to
use. We had to substitute the tilt switch that the original design asked for
with a push button which caused a few problems. Overall the circuit did do its
job which was nice but it would sometimes just start cycling through numbers,
because of a faulty push button. To fix this issue we placed the wire from pin
6 in the same row as the ground wire. I think the circuit could be even better
if you could incorporate RGB LEDs. Overall, the project was a lot of fun to put
together and troubleshoot.

Schematic:



Final Product:


20151020_093525.jpg20151020_092625.jpg
author
Tschec713 made it! (author)2015-08-28

Glad I found this, I was working on the same thing and was having a
hard time generating a random number. Now it works, Thank you

IMG_20150828_135357.jpgIMG_20150828_135408.jpg
author
bul0019 made it! (author)2015-08-05

Thanks for the instructable

IMG_5076[1].JPG
author
rolandosd made it! (author)2015-07-16

I Made it!!!! It did not ended as pretty as yours but at least it work hahahaha

IMG-20150715-WA0007.jpeg
author
nullf0x (author)2015-07-05

n

author
partho222 (author)2015-05-21

author
inktomi (author)2015-05-02

finish this project with some boy scouts. basic starter kit, couple extra LEDs, 2 hours working with the boys. I liked some of the type o it allowed for troubleshooting. great starter project

author
raulcorde (author)2015-04-18

It works!! But i think there is an error in the code, at pin set:

int pinLeds3 = 7;
int pinLed4 = 8;

Should be:

int pinLeds3 = 8;
int pinLed4 = 7;

I'm going to try with a tilt switch as you suggested.

Thanks!!

la foto.JPG
author
Emersonian (author)2015-03-25

author
DarrenXu (author)2014-08-15

我也做了。

temp_1326024418.jpg
author
ruhliar made it! (author)2014-07-11

Thank you I made it.

DSC_0620.jpg
author
ishan udyoga (author)2014-06-25

i made it online works fine. u can simulate it here...http://123d.circuits.io/circuits/253088-dice/

author
Xenia_mix made it! (author)2014-05-21

it was fun! thanks for the instructable :)

2014-05-21.jpg
author
Ploopy (author)2013-10-26

cool

i just made one!

author
PapaBA (author)2013-09-23

I got involved with Arduino a month ago after years away from hands on coding & electronics. Building, troubleshooting, & expanding this project was a great contribution to my learning. Thanks.

author
PapaBA (author)2013-09-23

Some say 2 of the LED groups should be assigned as:
// Led pins ...
int pinLeds3 = 7;
int pinLeds4 = 8;
which is correct to the SCHEMATIC & the final code, BUT ...
the ILLUSTRATIONS differ on this so ...

Others (like me) said the opposite:
// Led pins ...
int pinLeds3 = 8;
int pinLeds4 = 7; (we followed the ILLUSTRATIONS & adjusted the code)

Either way should work IF ...
our version of LED assignments matches our circuit connections.

author
PapaBA (author)2013-09-22

Thanks for posting this.
kloptops post confirmed for me that the code needs to be
// Led pins ...
int pinLeds3 = 8;
int pinLeds4 = 7; (reversing the last 2 pins)

I enjoyed blending your approach with Binary_Dice_Game by Maik Schmidt
http://media.pragprog.com/titles/msard/code/BinaryDice/DiceGame/DiceGame.pde
-----------------------------------
Code & illustrations by you & klopstops helped me see patterns to create a output_result() function using boolean logic instead of if:

void output_result() {

digitalWrite (pinLeds4, HIGH && (ran % 2 == 1)); // Odd Numbers light middle dot

digitalWrite (pinLeds3, HIGH && (ran >= 3)); // > 2 also light lower left & upper right

//Numbers even or 5 or 7 (winner) also light upper left & lower right
digitalWrite (pinLeds1, HIGH && ((ran % 2 == 0) || (ran == 5) || (ran == 7)));

digitalWrite (pinLeds2, HIGH && (ran >= 6)); // Number 6 or 7 (winner) also light mid left & right

delay(time);
Clear_LEDs();
}

// LEDs off (no button pressed OR clear display)
void Clear_LEDs () {
digitalWrite (pinLeds1, LOW);
digitalWrite (pinLeds2, LOW);
digitalWrite (pinLeds3, LOW);
digitalWrite (pinLeds4, LOW);
}

author
tecnocubeguy (author)2013-07-20

Instead of using 7 separate resistors for the leds, couldn't you just hook all their cathodes together, then hook them up to ground through a single resistor? If not, could you please briefly explain why it wouldn't work?

author
teknohawk (author)2013-04-18

Wow thanks! This is something I definetly want to build! :0 ;) :) Yay!

author
mr.future11 (author)2012-10-08

finally did this project it was nice starting with dice. but i want to blink led blindly before the no comes on after pressing the button. i tried it but it was not as good as i thought of.

P081012_1330[02].jpgP081012_1330[02].jpg
author
Davide311 (author)mr.future112012-10-24

Well done! For making leds blink like a dice before you press the button, you can try the modified code posted by "kloptops" some time ago. This is the link: http://dl.dropbox.com/u/7992054/arduino/Dice.pde
It' not a really "random" sequence, but i think it will work the same.
If you use that code, remember to change the code in the first lines from:
int pinLeds3 = 8;
int pinLeds4 = 7;
to:
int pinLeds3 = 7;
int pinLeds4 = 8;

author
mr.future11 (author)2012-10-08

made it finally. first project in arduino.. guys want help i want to blilnk leds randomly before the led show the no after pressing. i tried it but wasnt satisfied with it. so if anyone could help then please

author
Lendss (author)2012-07-24

I built one but it didn't worked well, so i looked
int pinLeds3 = 7;
int pinLed4 = 8;
and in this way my dice don't works well, but with
int pinLed4 = 7;
int pinLeds3 = 8;
it works perfectly.
Probably it's my fault but can you check it?
Thanks a lot
P.S. Awesome project

author
_-MacGyver-_ (author)2012-06-21

If you follow the schematic "correctly", this is the proper definition for the program. As my friend so cleverly noticed. Still an epic circut. Time to play RISK

//Led pins
int pinLeds1 = 10;
int pinLeds2 = 9;
int pinLeds3 = 7;
int pinLed4 = 8;
//Button pin
int buttonPin = 6;
int buttonState;
//Ran will be randomized from 1 to 6
long ran;
//Time is the time of delay
int time = 2000;

author
Davide311 (author)_-MacGyver-_2012-06-25

Whoops! Thank you for the correction, i just fixed it!

author
WakeUpWolfgang (author)2011-12-19

Very nice instructable it was easy to fallow along and do. I love it! Now I will try to make a shield for it, I will post photos of the shield when I get parts to make the shield.

author
Davide311 (author)WakeUpWolfgang2011-12-25

Great idea, and thank you for the interest! Ask if you need some help

author
WakeUpWolfgang (author)Davide3112011-12-25

I got the rest of the parts for it yesterday but we had to use my soldering room for some people to stay over but I should have it done some time this week I will post photos of it when its done.

author
Davide311 (author)WakeUpWolfgang2011-12-25

Ok, if you want i can add your photos in the instructable...and Merry Christmas!

author
FinalTrigger (author)2011-11-23

Sorry for the noobish question, can someone explain to me whats the significance of :
randomSeed(analogRead(0));
and
ran = random(1, 7);

Much appreciated. By the way this is a fantastic project to learn with.

author
Davide311 (author)FinalTrigger2011-12-25

Sorry for the waiting!
" randomSeed(analogRead(0)); " is needed for have a correct randomness (without it, the arduino will use the same sequence every time).
" ran = random(1, 7); " set the variable "ran" equal to a number from 1 to 6, that is the result.

author

With my limited programming experience im guessing "randomSeed(analogRead(0));" is preparing the program to create a random number and "ran = random(1,7);" is setting ran (a variable?) equal to a random number valued 1 through 7

About This Instructable

147,266views

278favorites

License:

More by Davide311:Arduino Led Dice
Add instructable to: