How To Write Your Own 4x4x4 LED Cube Show For Arduino

There are Many Instructables out there teaching you how to build an LED cube, however only a few actually help you write the code to go with it but rather just give you some to use, thus stopping your creative potential! Also there are many different ways to program the cube, but this is one of the simpler ways i found so far. If you don't know where to start start here!

This instructable will be an "addition" onto my previous one on how to make the LED cube itself. It can be found HERE.
For those of you that building my cube consider this the last few steps.

This instructable assumes you either know how a LED cube works or have built one yourself.

Also I assume that you have built a 4x4x4 cube (because that is what I have to take pictures of). however this will work with any cube if wired properly. 

Note that the code and cube run on Arduino.

Things Needed:
  • An LED Cube 
  • An arduino mega or uno, according to cube size
  • Arduino IDE
  • Computer
  • A fair amount of patience and time

Video of code i wrote(Show 2):

Remove these adsRemove these ads by Signing Up

Step 1: Setting Up Cube

For the main construction of the cube refer to my other instructable here.

However, we are going to change some things with the setup.
First off the transistors i used are not needed for these types of codes. Don't cut them, but just tuck the wires to the side and ignore them. They are still needed for some other codes.

In this setup run wires directly from the ground layers directly into Arduino. Notice in Photo one i just tapped into the ground solder lines that go to the transistor board. (Red trails are solder on other side)

Then the wire go directly into the arduino where the transistor board used to connect. (Photo 2)
I color coded them for easy connections.

The 16 Columns are all wired the same as they were before. 

Find the part in the code that looks like this:

int LEDPin[] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 14, 15};
int PlanePin[] = {16, 17, 18, 19};

The order the pins are listed changes the order they are in the code, so change this to fit your needs.

Once you have your cube set up properly move on to the next step. 

varooj.pink19 days ago

tnx I love it

Michael_Bell3 months ago

Did you ever figure out who wrote the original code? I made a web application for editing these animations, and I would like to know who to credit :)

hwillard10 months ago

I bought the parts to build this on ebay as a kit. The seller was from over seas. This is my first time doing one. Sounds like I built the cube backwards.

I have wires going directly to the Arduino Duemilanove. I don't have transistors. I believe I had (4) 2N3904 NPNs hooked up originally. Looking at that, do I need to use PNP Transistors instead; since it is wired backwards. Or is there a change that can be made in the code.

I appreciate the time, I have been pulling my hair out. Great instructable by the way.

jtmanders (author)  hwillard10 months ago

I dont think in the long run the fact they are backwards will make much of a diffrence. Because the whole concept it to complete the circuit which is done either way.

Good, my code does not use any transistors.

Since it was a kit, did it come with any type of instructions? or its own code?

jtmanders (author)  jtmanders10 months ago

And thanks!

hwillard10 months ago

Ok, I built the cube, wired it all, started doing code. I can make a code for it to light top layer then 2nd, 3rd, 4th in order. I, however, cannot figure out what to write to do the columns, nor can I figure out how to write code to do each corner, also, is it possible to light one led at a time.

my layers are using anode (+) hooked to pins 13,1211,10, cathodes (-) are columns using pins 0-9 and 14-19. Arduino Duemilanove.

Here is first lines of code:

B0001,B0000,B0000,B0000,B0001,B0000,B0000,B0000,B0001,B0000,B0000,B0000,B0001,B0000,B0000,B0000,35, //TOP
B0010,B0000,B0000,B0000,B0010,B0000,B0000,B0000,B0010,B0000,B0000,B0000,B0010,B0000,B0000,B0000,35, //SECOND
B0100,B0000,B0000,B0000,B0100,B0000,B0000,B0000,B0100,B0000,B0000,B0000,B0100,B0000,B0000,B0000,35, //THIRD
B1000,B0000,B0000,B0000,B1000,B0000,B0000,B0000,B1000,B0000,B0000,B0000,B1000,B0000,B0000,B0000,35, //BOTTOM

Please help.

jtmanders (author)  hwillard10 months ago

Ok, from the info you have given, it sounds like a hardware problem to me. Because technically to light an entire layer the code would be


Which turns on all of level one.

The lines of code you have posted above, given the hardware is correct, would light single columns.

Think about it logically, every 1 stands for an on light, every 0 stands for an off on. Therefore to light up an entire layer, there must be at least 16 on, or 16 1's in the line of code.

What you have written above is the correct code to light up single columns. The fact they are lighting up entire layers says something is wrong with your cube wiring.

Things to try:

Make sure you are bypassing the transistors.

One thing that struck me was that "my layers are using anode (+) hooked to pins 13,1211,10, cathodes (-) are columns using pins 0-9 and 14-19." Because that sounds backwards... the layers should share a common ground(cathode) and the columns should share common anodes. However, this might not be influencing it as theoretically this might not matter...I honestly don't remember.

Make sure you set the code to go with your cube. Refer to step One.

Hope this helps!!!

Tyler140611 months ago
Hey, I'm planning to re build my one of these but with RGB common anode LEDs
I really want to have a working code before I build it as they're more expensive and time consuming.
What I want (plan) to do is as they're common anodes, the 16 columns will remain as normal, but I will make 12 layers instead of 4,
I.E TopRed, TopGreen, and TopBlue,
2ndRed, 2ndGreen, and 2ndBlue,
3rdRed, 3rdGreen, and 3rdBlue,
BottomRed, BottomGreen, and BottomBlue,
With this, I would be able to not only control a single LED, but also decide if it's red, green or blue or all 3.
Problem is I'm not very experienced in Arduino and don't know how to do this.
If you or anybody you know would be able to help me or point in the right direction, that would be fantastic, I'd *LIKE* to keep the code in the B000, B000, B000.. etc format but if it's impossible so be it. I'd also not rather use any other IC's besides the arduino. Basically I want to know how to write a code for a 4x12 LED cube.. If you could help that would be appreciated.
jtmanders (author)  Tyler140611 months ago
Honestly, I have never researched about RGB cube.. I have no idea how to begin with a code like that. I'm sure there's one out there though, so look around. Sorry I'm no help. Good luck
gazza12331 year ago
this has saved me so much time as i could not figuer it out im ok with building stuff just not that good at the program stuff would this work with an 8x8x8 thank you
jtmanders (author)  gazza12331 year ago
Technically it would work with an 8x8x8, however there would not be enough I/O pins on any arduino. So if you make an 8x8x8 I suggest you do what I did and follow chrs instructable. I made an 8x8x8 following his, so if you have any questions ask away.
jtmanders (author)  jtmanders1 year ago
Oh and the code would probably work I don't really know, just very time consuming and relies on the hardware you make
Tyler14061 year ago
This was great ! I followed your first instructable to make the actual cube but as you said, it's only really doing codes that others have wrote. I sort of had an idea how the code works but never really looked into it, thankyou for clarifying this and making one of the easiest cubes without tons of work i.e shift regulators and the works. By far the best 2 instructables on an LED cube I've found. Hopefully will see an 8x8x8 one soon ;)
jtmanders (author)  Tyler14061 year ago
Hey thank you! 
Well ten you will be happy as I am making one right now! I am following chrs instructable, but I hope to make one for complete beginners guide and explain everything further In depth. Hopefully with some better schematics too.
If you want any help with that, let me know. I am the one that wrote the 8X8X8 cube revisited instructable.
Awesome ! I can't wait until it's done so I can make one for myself ! That's good seeing as all the ones on here aren't very detailed especially in the schematics. Looking forward to seeing it !
'earl1 year ago
Hey, voted for this. I have a 4x4x4c cube and this was the code type I found to make it work. Very time consuming but I have quite a few animations for mine and this inspired me to re program it and add new animations. Running out of ideas however.
Tyler14061 year ago
Awesome ! I can't wait until it's done so I can make one for myself ! That's good seeing as all the ones on here aren't very detailed especially in the schematics. Looking forward to seeing it !
maewert1 year ago
Nice instructable. 

I am sure there are many other methods of accomplishing the same thing. 
In my 5x5x5 cube I put all of the LED cycling code into an interrupt routine which is called based on a timer.  This way I can be sure all of the LEDs will appear the same brightness since the 'on' LEDs will have the exact same duty cycle without using any busy-loops (i.e. delay(x) routines).

I also abstracted the code so the software has simple set and check routines ( like: setOn(x,y,z), setOff(x,y,z), isOn(x,y,z), isOff(x,y,z)  where the x, y, and z are which LED in the three dimensions you wish to access). 

Then I can show a ball bouncing in the cube, or filling up with rain, or a snake roaming around inside it, etc. always changing directions based on the pseudo-random number calculator.  I can have letters scrolling through the cube received from the serial port (which requires more LEDs than your 4x4x4).  It allows a more traditional programming than sets of pre-defined canned images.

As I said before, lots of ways to do it, each has its advantages and disadvantages.

Best Wishes.
jtmanders (author)  maewert1 year ago
Thanks for the comment! That a great idea! I knew there were many ways to go about this, this is just the first things I figured out. I'm sure there is someone out there like me that had no idea where to start, so this is a good starting point anyway.