This project started out with a bag of LEDs that I had removed from flashlights, to convert to UV flashlights. I knew I would find something fun to use them with, but It was months before I figured out what to do with them. When I saw an LED cube on youtube, I knew what to do.

I had about 70 LEDs, and an arduino. I wanted to build the cube with stuff that I already had, and using as little new stuff as possible. I built my using 64 LEDs, and 4 resistors and I would have used bus wire, but I didnt have any, so I used galvanized steel wire from the hardware store (baling wire?). I had to use wire to connect the LEDs, since had been clipped to about 1/8" lead length. To connect the LEDs to the arduino, I used an old IDE cable, because its so convenient for transferring parallel data. I was going to need 20 wires, so one ribbon cable keeps things tidy, and easy to trace. I did this project on a holiday weekend, and I wasnt able to acquire a SIP header, but I was able to make due with a couple paper clips, straightened, and clipped to about 1/2".

I had some problems finding software that would work, because I made my cube common anode, Instead of common cathode (I was thinking of only using 4 resistors, and thought they should be on the positive side, not the negative side...) Since my cube was made up of 4 layers of 16 columns, I used 4 220ohm resistors on the plane pins instead of 16 resistors on the column pins. I figured I could always change the code, but that turned out more challenging than I had anticipated. I have since revised my cube to use 16 100 ohm resistors, instead of the 4 220s, and It is much more evenly lit.

It should also be noted, that the LEDs that I used were in circuits with 3 batteries, they seem to run at about 4.5v. When re-using IDE cable, every other wire is one side of the connector, so if you only use one side (like Im doing), you only use every other wire, this also turned out to be quite handy when hooking up 2 8-bit shift registers.

This worked great, but it used all the pins on my arduino, and I wanted to try to add things, things that will need some of those precious pins. The arduino had some nice programs for using shift registers (74HC595s specifically), so that is what I used.

There are many examples of using LED cubes, so I wont go over that part, this is about converting the cube from parallel to serial using shift registers. With the new code, and use of shift registers, you can expand this cube to virtually any size, you can also add features (buttons, knobs, sounds, sensors, motors,...)

This project needs:

1 4x4x4(64) LED cube, assembled, and working.
2 74HC595 Shift Registers.
1 IDE cable
9 SIP header pins.
Arduino + USB cable + computer to program.
1 USB cell phone charger (to power the cube when not hooked up to the computer.)
You will  also want some kind of container, or board to mount your project.

Soldering iron/solder/flux/alcohol (Soldering and cleanup)
Tweezers, Pliers, Diagonal nose cutters, knife (for wire and chip prep)

Step 1: Build and test an LED cube.

Step 1 Build and test an LED cube.

Follow one of these instructables, and build yourself a 4x4x4 LED cube, or build a different size cube, and modify the software to suit your cube size.
If you build a 4x4x4 or smaller cube, you can hook it up(similar to the way shown above), and test it out, and test the software. If you want to build a bigger cube, you should probably start with a smaller cube first, then move on to bigger, after you have some experience with the smaller cubes.

Links to 4x4x4 cube Instructables


<p>I know this forum is a little out dated, but Im hoping for the best! Im down to the last few lines of page 11 that I have had to fix some very minor things but for some reason I can't figure out the following. I'll start from the void loop. </p><p>// display pattern in table until DisplayTime is zero (then repeat)</p><p>void loop()</p><p>{</p><p> // declare variables</p><p> byte PatternBuf[PLANESIZE]; // saves current pattern from PatternTable</p><p> int PatternIdx;</p><p> byte DisplayTime; // time*100ms to display pattern</p><p> unsigned long EndTime;</p><p> int plane; // loop counter for cube refresh</p><p> int patbufidx; // indexes which byte from pattern buffer</p><p> int ledrow; // counts LEDs in refresh loop</p><p> int ledcol; // counts LEDs in refresh loop</p><p> int ledpin; // counts LEDs in refresh loop</p><p> int pinState; //pinState is used to send the correct bit to the data pin</p><p> // Initialize PatternIdx to beginning of pattern table</p><p> PatternIdx = 0;</p><p> // loop over entries in pattern table - while DisplayTime&gt;0</p><p> do {</p><p> // read pattern from PROGMEM and save in array</p><p> memcpy_P( PatternBuf, PatternTable+PatternIdx, PLANESIZE );</p><p> PatternIdx += PLANESIZE;</p><p> // read DisplayTime from PROGMEM and increment index</p><p> DisplayTime = pgm_read_byte_near( PatternTable + PatternIdx++ );</p><p> // compute EndTime from current time (ms) and DisplayTime</p><p> EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;</p><p> // loop while DisplayTime&gt;0 and current time &lt; EndTime</p><p> while ( millis() &lt; EndTime ) </p><p> {</p><p> patbufidx = 0; // reset index counter to beginning of buffer</p><p> // loop over planes</p><p> for (plane=0; plane;); // turn previous plane off (low is off, high is on)</p><p> if (plane==0) </p><p> {</p><p> digitalWrite( PlanePin[CUBESIZE-1], LOW );</p><p> } </p><p> else </p><p> {</p><p> digitalWrite( PlanePin[plane-1], LOW );</p><p> }</p><p>/*</p><p>// load current plane pattern data into ports</p><p>ledpin = 0;</p><p>for (ledrow=0; ledrow for (ledcol=0; ledcol digitalWrite( LEDPin[ledpin++], PatternBuf[patbufidx] &amp; (1 &lt;&lt; ledcol) );</p><p>}</p><p>patbufidx++;</p><p>}</p><p>*/</p><p>// I used code from shiftout, to redo this to serialize the plane data</p><p>//ground latchPin and hold low for as long as you are transmitting</p><p>digitalWrite(latchPin, 0);</p><p>//move 'em out</p><p>ledpin = 0;</p><p>for (ledrow=0; ledrow;); for (ledcol=0; ledcol;);</p><p>digitalWrite(clockPin, 0);</p><p>// digitalWrite( dataPin, PatternBuf[patbufidx] &amp; (1 &lt;&lt; ledcol) );</p><p>if (PatternBuf[patbufidx] &amp; (1 &lt;&lt; ledcol))</p><p>{</p><p>pinState= 0; // Flip these bits to suit your cubes common lead (cathode or anode)</p><p>}</p><p>else</p><p>{</p><p>pinState= 1; // Flip these bits to suit your cubes common lead (cathode or anode)</p><p>}</p><p>//Sets the pin to HIGH or LOW depending on pinState</p><p>digitalWrite(dataPin, pinState); // this is where data is sent to the shift register.</p><p>//register shifts bits on upstroke of clock pin</p><p>digitalWrite(clockPin, 1);</p><p>ledpin++;</p><p>}</p><p>patbufidx++;</p><p>}</p><p>****************************************************</p><p>but this line below is whats give me proplems. says something about putting in a 'while' so I do, but then it says &quot;could not convert 'digitalWrite(((uint8_t)latchPin), 1u)' from 'void' to 'bool'&quot;.</p><p>digitalWrite(latchPin, 1);</p><p>****************************************************</p><p>// turn current plane on (plane high for on)</p><p>digitalWrite( PlanePin[plane], HIGH );</p><p>// delay PLANETIME us</p><p>delayMicroseconds( PLANETIME );</p><p>} // for plane</p><p>} // while } while (DisplayTime &gt; 0); // read patterns until time=0 which signals end</p><p>}</p><p>So, if someone wouldnt mind helping me out!!</p><p>Thanks A Bunch!!</p>
<p>The repaired code may be posted below somewhere, I havnt looked at this code in a long time, and would prefer to not look at it, its kind of ugly.</p>
Hi, I built my LED Cube with a common cathode and I can only find scripts for common anode arrangements. Is there any difference between the two and if there is, can anyone help me figure out the code for a common cathode arrangement?
Reading the common cathode code, I cannot find which are the arduino pins to connect the registers. Are the 16 columns supposed to be conected directly on the arduino? I do not see the clock and latch, nor DS out, can anyone help me?
<p>Ok I've misreading, but the real code does not compile :c</p>
<p>Ian, you are correct, the posted code on page 12 is wrong on several lines.</p><p>In fact each line that contained a '&lt;' is truncated and joined with next line.</p><p>Use the code on page 11 looks OK, but the missing formatting (indentation) makes it hard to read.</p><p>@HippyNerd: to support your audience you perhaps post the code in a zip file, so the formatting is maintained and no copy-paste errors do occur.</p>
<p>Yeah, I've been noticing that formatting gets ugly when pasting code. I think that if I attach a file, it doenst have to be compressed plain text should keep its formatting. I will have to repair the cube before I can test any software though :(</p>
<p>Somehow, I managed to repair the code:</p><p>Going thru forums, I found some old code of you. I used it as a guide to change and delete some lines.</p><p>But now, I've formatted my pc so I need to search beneath my backups the code. I guess tomorrow or so I'll upload it if I can.</p>
<p>This code is pretty hacked up, It was kinda hacked up when I got it, and then I did terrible things to it. Its amazing that it works! <br>This cube design lacks transistors for the planes, which means that the plane pins on the microcontroller are going to take a pretty high load (upto 16 LEDs at one time). I think I also later modified my cube to have resistors on the 16 LED leads. <br>Honestly, If I was building this cube now, I would use resistors on all 16 LED leads, and transistors on the plan pins. Cleaning the code up would be real helpful too. Making a program to do patterns would be a big benefit also.</p>
<p>You (all) should not build this without the 16 current limiting resistors; otherwise the current will be <br> uncontrolled high and will overstress the capabilities of the AVR I/O <br>pin, and that of each LED. There is no real need to use 16 transistors on the data pins because each sinks or sources only one LED at a time; the AVR I/O pin can handle up to 20mA, although the combined current (16x20=320mA) is a bit much for the AVR common power pins. On the 4 planes you must use transistors because it can sink or source the current of up to 16 LEDs at a time.</p><p>The resistors have to be calculated such that the LED current is not more than 20mA. For the High intensity LEDs you may calculate for 1 or 5 mA each, unless blinding the audience is intentional. </p>
<p>I would use 4 transistors, one for each plane pin.<br>the resistor value, and the current would depend on the LED. most 5mm are 20mA, but you should check the LEDs you are using.<br>Another option would be to run the LEDs with bigger resistors, so that the plane pins are under 40mA. </p>
<p>This was my current scheme (I finished this project on the early December).</p><p>I guess that some connections on the ICs are a bit unclear but still is undertandsable. The real cube worked 100% perfect.</p>
<p>Hi I noticed that in the pic above, it is arduino leonardo..... But can I use arduino Uno as well?</p>
<p>Yes, you can use any other Arduino as long as it has enough pins. Just &quot;rewire&quot; them from the code itself. Good luck!</p>
<p>That looks real good, although it would be better to put resistors between the LEDs and shift registers *(value would vary, depending on he LEDs used.)<br><br>It looks like the shift registers also need 5v and gnd. </p>
<p>I missed something here: the 16 databits are not on the AVR but on two 8-bit shift registers. When using 74HC or 74HCT series, the LED current shall be below 5mA each, and the resistors shall be calculated accordingly.</p>
<p>Yeah, the original cube that I built was run directly from the microcontroller. the whole point of this instructable was converting it to use shift registers instead, to free up I/O for other things. </p>
<p>Well, I've found the modified code that I used insert in one of my reports to the university as a plain text.</p><p><a href="https://www.mediafire.com/?02lpgwkvg1z4uay" rel="nofollow">https://www.mediafire.com/?02lpgwkvg1z4uay</a></p><p>I can't test it right now because I borrowed the ICs from the faculty :\ But should work.</p><p>Also, there is a pretty page that does patterns in a graphical mode for the cube. </p><p><a href="http://www.robota.nl/en/blog/led-cube-4x4x4-pattern-designer/led-cube-simulation-and-pattern-generator.html" rel="nofollow">http://www.robota.nl/en/blog/led-cube-4x4x4-patter...</a></p><p>And finally, a video of mi cube working using the modified code and the demo pattern of the last web.</p><p><a href="http://www.dailymotion.com/video/k2qpnoNiwjAlDF9rvrS" rel="nofollow">http://www.dailymotion.com/video/k2qpnoNiwjAlDF9rv...</a></p>
<p>This is great Igan. I think that you make an instructable with all your improvements. You can use my pictures, code, whatever you need to make it easier or better.</p>
I have no idea why you are having trouble, Its pretty hard to say from here.
There are many ways that you can build this cube. This cube started out like you mention, with 16 columns that are each connected to an arduino pin. This instructable is about converting that LED cube to use 2 shift registers instead of 16 pins on the microcontroller.<br>Its been a couple years since I worked on this cube, so I have to go by my comments in the code, lets hope they are correct:<br>int dataPin = 7; //Data I added these for Shift Register<br>int clockPin = 12; // Clock<br>int latchPin = 13; // Latch<br>
<p>I'm using common cathode version, so the first time I've misread and use the original code (from page 10) instead from the CC one (from page 12, the last page). Also, I'm using Arduino Leonardo, but however is very very very similar to Arduino UNO.</p><p>But when I try to compile the last code I get this error:</p><p><a href="http://i.imgur.com/oKWZ5Tm.png" rel="nofollow">http://i.imgur.com/oKWZ5Tm.png</a></p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p><p>Arduino: 1.0.6 (Windows 7), Board: &quot;Arduino Leonardo&quot;</p><p>sketch_nov20a.ino: In function 'void setup()':</p><p>sketch_nov20a:237: error: expected `;' before 'pinMode'</p><p>sketch_nov20a:237: error: expected `)' before ';' token</p><p>sketch_nov20a.ino: At global scope:</p><p>sketch_nov20a:239: error: expected declaration before '}' token</p><p>I guess that is related to grammar inherent to C/Processing language, but this is my very first time using Arduino and programming, so I dunno how to fix it :\</p><p>Thanks in advice.</p><p>(Also pardon me if my english is a bit poor, is not my native language)</p>
<p>Good write up. I built the cube with common cathode for each layer. I ran your code, but it really only ran 2 dimensionally. If any bit on the column is on than the whole column is on. doesn't seem to be turning on and off each layer. I believe I wired it correctly and if disconnect one of the layers it doesn't work. Is your code turning off each layer before turning on the next? Thanks, for your work.</p>
<p>OK, I found the issue in the code. The two &quot;HIGH&quot; settings below (about halfway through the void loop) should <br> be set to &quot;LOW&quot;, then it will work with common Cathode configuration. <br> digitalWrite( PlanePin[CUBESIZE-1], HIGH );<br> } else {<br> digitalWrite( PlanePin[plane-1], HIGH );<br> }</p>
Is it possible you built the common anode version? Do your LEDs light up the opposite of what you might expect? <br>I havnt worked on that cube in over a year, and I cant remember the details as well as I did when I built it. <br>The primary difference between the common anode and common cathode versions are the lines you mention, and the data, the data is the opposite (1s where it should be a 0). <br><br>Someday I may have to build both cubes and test the software. <br><br>If you can send me a copy of your working code, I can compare it and edit mine, but I need to build another cube to test it.
<p>Mine is common cathode. However, I did sink mine using NPN transistors, so that may affect the outcome. It is working well now. I added some other binary data from other sources for a longer show. I also added a little rain routine, but need to make it a little more complicated to make it look good. Have some other ideas for the code and may go with a whole different approach.</p>
<p>It sounds like maybe you should write up an instructable too! <br>There are many ways to build this cube, the first way that I built it was nice because it used few parts. You could add a bunch of transistors to this cube to make it nicer on the microcontroller. <br>Transistors are awesome. I have a 4 x 4 x4 RGB cube that only uses 20 NPNs and 20 resistors and an arduino.<br>Would you be interested in sharing your code? I would like to try the new data on my cube. Also seriously consider writing something up showing how you did things differently, that would be awesome.</p>
<p>Of course I will share any changes to code or my own code, but I need to clean it up a bit. Some of the operations need to be placed in functions. It will make the code easier to understand, manipulate and add-on to. I will let you know. </p>
Is your common cathode version not finished? the code doesnt compile, seems to have a few missing parts!
Hrm. I wonder what the problem could be. If I remember correctly, i built a common cathode cube, and thats what I ran my code on. <br>I havnt messed with that cube in about a year, so my memory isnt too fresh on the details.
Check it out at the begining, the &quot;#include // allows use of PROGMEM to store patterns in flash&quot; <br>Missing part there, <br>and a few other places. I compared it to your other code and fixed it.
Ah, yes, now I see the include line that didnt include the file to include. <br>I edited that one line of the CC code, please try it, and let me know if it works. I dont have a CC cube to test it on myself. It turns out my cube was CA.
Hi <br>Do you have an actual schematic for the 4x4x4 cube with shift registers. <br>I have a 4x4x4 cube and was wanting to convert it to running with shift registers. <br> <br>Thanks <br>W
I did not make a schematic. The way the shift registers are wired, is exactly the way used in the arduino shiftout tutorial with 2 cascaded shift registers. <br>In step 7, there is a link to a webpage about using shift registers, use those fritzing images for reference. <br>Pins 1-7 are output, Pin 8(gnd) and 13(OE) are connected to ground, pins 16 (+5v), and 10(SRCLR) should be connected to +5v. The data (pin 14)from the second chip connects to the the first chips pin 9. The rest of the pins should connect to an arduino, or to a resistor/LED. I may be able to make a schematic, but that may take some time to get done.
Hi <br>On both of your shift register codes they say for Common Anode. Was one supposes to be for Common Cathode?
Good catch! I had edited the code, but not the comment at the top. I have changed that in the instructable, and my copy of the code. <br> <br>Thank you for your help. <br> <br>P.S. A better way to deal with the common anode/cathode would have been to put a flag that the user selects, or have 2 lines, one of which gets commented.

About This Instructable




More by HippyNerd:RGB LED Car Dash, and Door Lighting Make a Pizza MHI Turbo Rebuilding and Modifications 
Add instructable to: