If you have looked at my 5 LED ATtiny85 POV display, we programmed the ATtiny with the Arduino. (If you haven't seen it, click here) We will be doing the same thing for this LED Dice project.

The total parts cost for this project is about $5-$10. (Not including the Arduino board and the tools.)

It is super simple to make, so don't worry if you don't have a lot of programming/ electronics experience.

This is a contest entry for the LED Contest with Elemental LED, so don't forget to vote for me! ;)

Step 1: Parts List

Here's all the stuff you need. You can get it all for 5-10 bucks if you buy from Mouser/Digi-Key.

1x ATtiny85/45/25 (8 pin DIP)
1x 8 pin DIP socket
1x Tactile pushbutton switch
1x 10K Ohm resistor
7x LEDs (I used clear, high-brightness red. We will be powering this with a 3 volt battery pack, so make sure you choose something that can handle that much power)
1x 2 AA/AAA battery pack (could also be a 3 volt CR2032 coin cell battery, just make sure whatever pack you choose that it's 3 volts)
Some perfboard
Batteries that go with your battery pack
Some wire

Arduino board (for programming the ATtiny)
USB A-B cable (for plugging in the Arduino)
Soldering iron
Thin solder
Helping hands (optional, but very helpful for soldering)
Something to cut down the perfboard to size (I used my Dremel)

Step 2: How It Works

At this point, you might be thinking that the ATtiny85 does not have enough input/output pins to drive 7 LEDs and read the input of a pushbutton.

If you thought this, you would be right, but there is a way around this.

If you look at a 6 sided die, you might notice that there are never 2 dots that aren't diagonal or across from each other that are not there at the same time (except for the middle one). That means that we can connect the top left LED to the bottom right LED, the middle left LED to the middle right LED, and the bottom left LED to the top right LED.

So now we only need 4 pins to control all of the LEDs (the 3 pairs of LEDs and the single middle one). That means we have one pin left over to read the push button. Perfect!

Step 3: Program the ATtiny MCU

If you read my Instructable on the 5 LED POV display, they you probably already know how to do this. For those of you that don't, here is a guide.

This is the code that you need to upload to the ATtiny:

int pinLeds1 = 3;
int pinLeds2 = 2;
int pinLeds3 = 1;
int pinLed4 = 0;
int buttonPin = 4;
int buttonState;
long ran;
int time = 2000;

void setup ()
  pinMode (pinLeds1, OUTPUT);
  pinMode (pinLeds2, OUTPUT);
  pinMode (pinLeds3, OUTPUT);
  pinMode (pinLed4, OUTPUT);
  pinMode (buttonPin, INPUT);

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 4: Breadboard It!

Now put it all on a breadboard and test it out. You can power it with any 3 volt power source. Make sure that the LEDs are arranged correctly!

Step 5: Solder It!

Now you can solder it onto your perfboard, if you would like. Be careful though, it gets kind of trick with all the LED wires/leads crossing, make sure they are not touching, or else your dice will not work.

Also, make absolutely sure that you connect/arrange the LEDs correctly, or else the LEDs will not light up the right way.

Sorry I couldn't take pictures of the soldering process, I made this Instructable after I completely finished the dice.

Step 6: Make It Look Nice!

I cut down the perfboard with my Dremel, and then used the sander bit to round off the edges. Then I hot glued the battery pack to the back of the perfboard.

Now it looks nice!

Step 7: Use It!

Push the button to make a random dice number between 1 and 6 appear on the LEDs.

Congratulations! You're done!
Yay, I finished my utterly complex one!<br>
Cool! is there an ATtiny in there somewhere or are you using the Arduino only?
Hi nice
<p>Hi xBacon,</p><p>Thanks for the fun little project. I decided to use Functionalize F-Electric, our conductive filament and see if I could print one of these as my first ATtiny85 project. I think it came out quite nicely. I powered it with 3 button cells, and also wrote a new sketch, which didn't turn off the ADC, but did go to sleep when not in use. Here's a video of the 3D printed dice in action.</p><p>https://www.youtube.com/watch?v=dLH4hKym9gU</p>
<p>This looks like a geat little project. I've never used the ATtiny before, and now I've ordered 10. This'll be the first project I'll use it for.</p>
<p>Thanks, made mine from an earphone case.</p>
I had to change over some of the pins in your code, This is what I had: <br>int pinLeds1 = 4; <br>int pinLeds2 = 1; <br>int pinLeds3 = 0; <br>int pinLed4 = 3; <br>int buttonPin = 2; <br>Works good.
Thats a pic of the one you made? Nice! I always like to run things on a smaller battery so its more compact, so i like how you did that.
This little guy works great but I revisited this last night, I found that the battery life wasn't as good as it could be due to the chip always ON even when not in use, now my code puts the attiny85 into a &quot;sleep&quot; mode and wakes up when you press the button, the button has to be wired differently, the Switch must pull the attiny85 LOW instead. Batteries can last a much longer now. but now I need a new PCB :)
<p>using a high precision multimeter I measured 1mA on the original circuit so about 8 days of battery on a CR2032(not going to sleep) I then put the attiny85 into sleep mode but was still measuring .25mA(about 30 days on the battery) so I then looked into how to make the attiny use even less power and found out I need to disable the ADC's etc so then we now have a battery life of 15+yrs assuming you push the button an average of 2x per hour every hour.. I also added a 10k resistors to each LED pair and re-wrote the code to be non blocking(no use of delay) and be MUCH MUCH more random... so with my code you hold the button down and the dice visually rolls(extremely quickly goes through all 6 sides randomly) then when you release the button it will display the rolled number for either 2 seconds or until you press the button again(so you could re-roll immediately after seeing number)</p><p>[code]</p><p>#include &lt;avr/sleep.h&gt;</p><p>#include &lt;avr/power.h&gt;</p><p>int pinLeds1 = 1;</p><p>int pinLeds2 = 4;</p><p>int pinLeds3 = 0;</p><p>int pinLed4 = 3;</p><p>int buttonPin = 2;</p><p>int buttonState;</p><p>long ran;</p><p>int time = 2000;</p><p>unsigned long lastmillis;</p><p>int i = 0;</p><p>typedef void (* NumFuncPTR) ();</p><p>NumFuncPTR number[6] = {One,Two,Three,Four,Five,Six};</p><p>void pin2Interrupt(void)</p><p>{</p><p> /* This will bring us back from sleep. */</p><p> /* We detach the interrupt to stop it from </p><p> * continuously firing while the interrupt pin</p><p> * is low.</p><p> */</p><p> detachInterrupt(0);</p><p>}</p><p>void enterSleep(void)</p><p>{</p><p> /* Setup pin2 as an interrupt and attach handler. */</p><p> attachInterrupt(0, pin2Interrupt, LOW);</p><p> delay(100);</p><p> set_sleep_mode(SLEEP_MODE_PWR_DOWN);</p><p> sleep_enable();</p><p> sleep_mode();</p><p> /* The program will continue from here. */</p><p> /* First thing to do is disable sleep. */</p><p> sleep_disable(); </p><p>}</p><p>void Blink(){ //was written for debugging but I left it in.</p><p> digitalWrite(pinLed4,HIGH);</p><p> delay(500);</p><p> digitalWrite(pinLed4,LOW);</p><p> delay(500);</p><p>}</p><p>void setup ()</p><p>{</p><p> //Disable stuff we dont need so we can entire extreme low power sleep(.1uA)</p><p> // Disable the ADC by setting the ADEN bit (bit 7) to zero.</p><p> ADCSRA = ADCSRA &amp; B01111111;</p><p> // Disable the analog comparator by setting the ACD bit (bit 7) to one.</p><p> ACSR = B10000000;</p><p> randomSeed(analogRead(1));</p><p> pinMode (pinLeds1, OUTPUT);</p><p> pinMode (pinLeds2, OUTPUT);</p><p> pinMode (pinLeds3, OUTPUT);</p><p> pinMode (pinLed4, OUTPUT);</p><p> pinMode (buttonPin, INPUT_PULLUP);</p><p> lastmillis = millis();</p><p>}</p><p>void loop()</p><p>{</p><p> buttonState = digitalRead(buttonPin);</p><p> while (buttonState == LOW){</p><p> buttonState = digitalRead(buttonPin);</p><p> time = 2000;</p><p> lastmillis = millis();</p><p> reset();</p><p> number[random(1,6)]();</p><p> delay(30);</p><p> }</p><p> if (lastmillis + time &lt;= millis()){</p><p> reset();</p><p> enterSleep();</p><p> }</p><p>}</p><p>void One(){</p><p> digitalWrite (pinLed4, HIGH);</p><p>};</p><p>void Two(){</p><p> digitalWrite (pinLeds1, HIGH);</p><p>};</p><p>void Three(){</p><p> digitalWrite (pinLeds3, HIGH);</p><p> digitalWrite (pinLed4, HIGH);</p><p>};</p><p>void Four(){</p><p> digitalWrite (pinLeds2, HIGH);</p><p> digitalWrite (pinLeds3, HIGH);</p><p>};</p><p>void Five(){</p><p> digitalWrite (pinLeds2, HIGH);</p><p> digitalWrite (pinLeds3, HIGH);</p><p> digitalWrite (pinLed4, HIGH);</p><p>};</p><p>void Six(){</p><p> digitalWrite (pinLeds1, HIGH);</p><p> digitalWrite (pinLeds2, HIGH);</p><p> digitalWrite (pinLeds3, HIGH);</p><p>};</p><p>void reset(){</p><p> digitalWrite (pinLeds1, LOW);</p><p> digitalWrite (pinLeds2, LOW);</p><p> digitalWrite (pinLeds3, LOW);</p><p> digitalWrite (pinLed4, LOW);</p><p>}</p><p>[/code]</p>
<p>So I thought it would be neat to build two of these on one board. After all most games use two dice. Anyway I have one double DPDT switch turn the power on both circuits at the same time. Well it turns out that both dice seem to almost always show the same value when you hit the switch to display a number. Since there is no clock or anything unique to make one randomize different from the other. So other than modifying one die with a variation on the random number generation, anybody got any ideas would be appreciated.</p>
<p>the code above tries to make a random seed by reading from ADC(0) with the line randomSeed(analogRead(0)); but there is two issues with this... I don't think the ATTiny45/85 has a correlating AnalogPin 0 in the Arduino IDE so this would need to be randomSeed(analogRead(1)); to read ATTINY pin7... but that still wont work to well because there is a connection on Pin7(aka arduino digital pin2) so its not floating and you wont get a very random value... but I would try that first and see what happens but you most likely will need to do something tricky and put the switch and the DigitalPin2 LED onto DigitalPin4(by switching the pin to an input checking for a button press then back to an output to display LED over and over again) so you can leave Analog Pin 1 floating so it will get random noise from the environment.</p>
Works great!!!
ok so i mad emy own version of this before i even saw this one and i seems to be the same pretty much, I used an ATtiny 85. if tried 3 different sketches and none of them work, is one only flashes a 3. Please help!?
Hi, I also made an LED dice out of an Attiny25, you may wanna look at my code, as mine makes the chip go to sleep after it finishes with the numbers and so the batery can last up to 80 YEARS! <br>you may wanna add some sleep functions to your code, I managed to get the power consumption to less than 0.1 microAmps!
No way! The battery would expire by then... <br>How does sleep work? I same with him <br>VVVVVV
yeah, thst's true, the actual self discharge of the battery is more tha the power needed by the chip itself, of course, what takes most of the battery's energy is the LEDs when they are ON.
Oh yeah, emihackr97, when i tried your code it messed up my ATtiny. It wouldn't let me upload any sketches to it but when it did it just didn't display any numbers when i pressed the button...
I don't know what could have happened, maybe you can just adjust the pins in my code to fit your dice. <br>BTW, I didn't use any resistors for the button.
Oh cool! I had a look at your code, but I dont quite understand how the whole sleep thing works. Maybe you could PM me and tell me how that works?
Yeah, it's really simple, once it is done diplaying the numbers, the chip goes to sleep, reducing power consumption to only 0.1 micro Amps, that's 0.3 microWatts! <br>then, the button is just an interrupt that wakes up the chip so it displays a new number.
@xbacon: No ATtiny in this one...still waiting for my order to arrive. For some weird reason, there is no reply button. (On that message. Weird...
This is an AWESOME instructable. Here are a couple of questions: -Can you give me some info on the ATtiny? I have an ATmegaXXX(don't remember three digit code, too lazy to go get the arduino) and I want to know about this ATtiny. Seems cool. -In you code with the if statements, wouldn't be easier to use a switch case <a href="http://arduino.cc/en/Reference/SwitchCase" rel="nofollow">http://arduino.cc/en/Reference/SwitchCase</a>
Thanks for the compliment! <br> <br>Here is some information about the ATtiny's. <br> <br>The ATtiny85 that I used here is a simple 8 pin AVR chip made by Atmel. The '85 version has 8KB built-in flash storage for storing your code. In comparison with the Arduino, the Uno version (which is the newest one) has an ATmega328 on it, which has 32KB of flash program storage instead of the 8KB that the ATtimy85 has. <br> <br>The ATtiny85 has 4 Analog input pins for reading data from analog devices such as potentiometers, force sensors and LDRs (light dependent resistors). The Arduino has 6 of them. The Analog pins on both the Arduino and the ATtiny85 can be used as Digital outputs also. <br> <br>The ATtiny has 2 dedicated Digital output pins, which are both PWM. The Arduino has 11, 6 of which are PWM. <br> <br>The 8 pin ATtiny's come in 4 kinds. The '85 has 8KB of program space, the '45 has 4KB of program space, the '25 has 2KB of program space, and the '13 has 1KB of program space. I always get the 85's because they are less than a dollar each on Digi-key and Mouser, and they usually have enough space to store some pretty complex programs. <br> <br>I could go on forever, but I'm going to stop here so I don't start to bore you. ;) <br> <br>Also, about the SwitchCase statements, I don't think the ATtiny's support it. They only support simple things like &quot;if&quot; and &quot;delay&quot; and &quot;digitalWrite&quot; statements. Correct me if I'm wrong.
Thanks. Just noticed something about those numbers:<br> <strong>32</strong>8 = 32 KB<br> <strong>8</strong>5 = 8 KB<br> The last digit is probably a model or something.<br> Those attinys are AWESOME!!! I believe that &quot;simple&quot; code is C, not C++ (arduino). And its pretty hard to bore me. Can you use the arduino volt reg, usb-serial bus, and stuff like that to run the tiny? By, like, connecting all the pins on the tiny to the arduino? Thanks, and that dice thing with the 4 pins is a GREAT idea!
You're right about the numbers. The ATmega168 that was used in the Diecimila and the old Duemilanove's had 16KB or space, hence the <strong>16</strong>8.<br> <br> Yes you can use the Arduino as a power supply for the ATtiny, just connect Vcc to +5v on the Arduino and GND to ground on the Arduino. You can plug the Arduino into a USB plug on your computer or from a wall to USB charger adapter, or you could plug a 9 volt battery into the DC jack and use it that way.<br> <br> I recommend using a 3v power source for smaller projects though. Here I use a 2x AA battery pack to power it. The ATtiny85<strong>V</strong>'s can take anywhere from 1.8 to 5.5 volts. The regular ATtiny85's without the V can take 2.7-5.5 volts.<br> <br> Thanks for the compliment (again)! haha
How did you go about multiplexing?
It's not really multiplexed, the LEDs are just wired in pairs. if you look at step 2, it explains how this works.
Thank you!

About This Instructable




Bio: I'm a big Arduino fan. I'm always looking for new and exciting things to do with electronics and Arduino. I also like video ... More »
More by xBacon:DIY Infrared Proximity Sensor (Arduino Compatible) Color Changing LED Tree Plug-in LED Color Fading Night Light 
Add instructable to: