Introduction: 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 built 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.

Also, I lay no clam to the code found in this instructable, I have simply altered an existing code that has been floating around the internet. My hope here is to further explain this code in a way that people which have no prior knowledge of coding can form and write their own shows. If you are or know who originally wrote this code feel free to contact me!

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 new pattern I wrote(Show 2):


Since the 4x4x4 cube I have built a 8x8x8 LED cube and interfaced it with an old IPod Nano to play music. The animations on the cube were simply programmed and timed correctly to correspond to the music.

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. 

Step 2: Download the Codes

Extract the files and read the READ ME.

And if you don't have Arduino IDE, Download it.

Step 3: Understanding How the Code Works

Before writing the code you must first have a full understanding of how it works.

This entire program is based off of one line of text:

     1         2          3        4          5         6        7          8          9         10        11       12       13       14       15       16

The 16 B0000 sets all represent a row of LEDs in the cube.
(The number under is the row number in relation to the code) refer to photo 2
Now don't confuse rows and columns. Rows are horizontal, columns are vertical.
Look at Photo 1

And the 10 at the end is the speed at which that frame is played.

Think of each line of code being a frame in a movie, if you slow it down there are individual pictures, but when sped up, its an animation.

Now lets break it down even further:
Each 0 is an LED, 1 is on, 0 is off.
For instance: B0000 is a entire row turned off, B1111 is an entire row turned on.

Now even further, you want to turn on an individual LED.
refer to Photo 3, it will be your best friend while doing this, write it down yourself. 
When looking at a row from the front, the first LED is the last 0 in B0000 
go look at Photo explain better than words.

For example, you want to turn on the bottom left hand corner LED on and everything else off.
it would look like this:

Play with this yourself, the more you experience it, the faster and easier you can program.


Step 4: Writing Your Own Show!

First off open open LED_1cube_4x4x4_Show_2 to make sure your cube is wired correctly. It should look like the video in the beginning.
Once verifying that, take a look at the code and how it is put together.
The only part that matters is the B0000 stuff. Everything else just don't touch.(with the exception of changing pin #)

Lets Write your first show!
Open LED_1cube_4x4x4_Blank_Show_
This is the show, but blank! 

There is one frame there to get you started and row numbers across the top.
To turn a LED on just replace some zeros with some ones! not much too it!
Copy and paste this over and over again and your set!

One last thing. 
Near the top you can find this:
#define TIMECONST 20
You can change the 20 to whatever number you want (its the time to view each frame in milliseconds).

Use this as a programming tool, slow it down a lot to look at individual frames to make sure everything is right or to figure out what is wrong. 

Step 5: Examples

All take place when looking from front.

Turn on bottom left hand light:
Photo 1

Turn on row 1:
Photo 2

Turn on all four corners: 
Photo 3

Turn on all of layer 1:
Photo 4

Step 6: Finishing Up

Hope this helps someone!
Took me a while to figure out how to do this, hopefully save everyone some time and headache.
Feel free to comment or message me!
Thanks for reading.


gk143 (author)2016-08-15


exit status 1

'prog_uchar' does not name a type


sollution this program

shanchya (author)2015-07-02

Sir, I am having a problem with your code, it says

"Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"

LED_1cube_4x4x4_Show_2:15: error: 'prog_uchar' does not name a type

LED_1cube_4x4x4_Show_2.ino: In function 'void loop()':

LED_1cube_4x4x4_Show_2:447: error: 'PatternTable' was not declared in this scope

'prog_uchar' does not name a type

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences."

Please help!

JSWheeler (author)shanchya2015-11-09

Change that line to this

const int PatternTable[] PROGMEM = {

Captain Thiele (author)JSWheeler2016-07-22

Yes, but when you do that it doesn't upload.

JSWheeler (author)Captain Thiele2016-07-22

Worked for me 9 months ago. Things might have changed.

san7776 (author)2016-07-15

Sir, I am having a problem with your code, it says

prog_uchar does not name a type

MuraliM18 (author)2016-02-22

Will the program work with audrino mega

pri0004 (author)2015-12-11

to do one at a time you need up down side code like 123wich will light the led one up two to the side and three up

Toggle252 (author)2015-05-09

Hello tjmanders!

Great post, good information.

I have a question that has been on my mind that I cant seem to solve (anyone please reply). After reviewing the code, the last part looks as though the entire cube is light up at once. Is this not drawing too much power from the arduino? is there some part of the code that I am not seeing that implements POV where only one led (or layer) is on at any given time?

J.W.N.R. (author)2015-01-27

Hi jtmanders. Thanks for the user friendly programming tutorial.

I understand the concept, but like hwillard my 4^3 cube's layers are connected to anode and my columns are connected to cathode resulting in my cube not working.

I built my cube using the KyleTheCreator's instructable (

It's probably a stupid question, but how do i alter your code to make it match my cube?

Thanks in advance.

MariusG1 (author)J.W.N.R.2015-03-19

Actually I think this is easy to solve. Assuming your cube is exactly the same and exactly the same wired but the only difference is you switched anodes and cathodes in your cube you would just need to add transistors between the arduino and the cathodes.

The backside with this is now you need 16 transistors, instead of the usual 4, but just adding these 16 transistors would seem to solve the problem and the code is the same.

J.W.N.R. (author)MariusG12015-03-20

Wow, thanks! I will definitely try that.

MariusG1 (author)J.W.N.R.2015-03-20

Your cube would be like this, but you remove the 4 transistors of the blue wires and just run the blue wires directly from the arduino to supply +5V to the 4 layers.

Then you put 1k resistors on the 16 red wires and then to the base of the transistors. And then you just add your led current limiting resistors before the collector pin of each transistor and then gnd every single emitter!

Hope this helps!

MariusG1 made it! (author)2015-03-19

I made it! I also created a program so that you can easily make patterns, it's available here, check it out!

2015-03-19 22.45.21.jpg
xgashi (author)2014-12-20

Hi.. thanks for sharing.
I made the cube. following your steps.. But leds arent bright enough.
Can u explain way u use 22k resistor for bases of transistors.

jtmanders (author)xgashi2014-12-20

The resistors are heavily dependent upon the LEDs you use, if they are dim simply exchange the 22k for some lower, maybe 10k?

Michael_Bell (author)2014-08-17

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 :)

pedro147 (author)Michael_Bell2014-12-16

Micheal_Bell - Yes this interested me too. I asked exactly the same question on the Arduino forum here There are plenty of people all over the net laying claim to this code and sorry to be a "doubting Thomas" but looking at the OP's other code example like _4x4_LED_Cube_Sequence_1 which is a low level beginner coding, I sincerely doubt the the OP wrote the more complex code examples that he is claiming are his. Sad really that people feel the need to plagiarise the work of another to make themselves feel important. Also I would be really interested in having a look at your web app for this code if you are willing to share it. I promise that I will not claim it as my own work :-)

jtmanders (author)pedro1472014-12-16

I never did lay clame to the code. I stated I am not the one who originally wrote it. The basis of this instructable was to teach people how to use this code, because it is not clearly stated anywhere on the internet. Therefore for someone that doesn't know what they are doing this provides a very simple solution. When I say I wrote them, I clame I wrote the program design and the light patterns found in the code. However, I did not write the foundation of the code. But as you said, no one knows where it came from or who wrote it.


pedro147 (author)jtmanders2014-12-17

Maybe it would be prudent to edit your Instructable and
reword the statement "Video of code I wrote(Show 2):" situated
above video titled "4x4x4 LED Cube (NEW CODE) This would differentiate
between you writing a code "pattern" as opposed to writing the actual
code itself, as there is a rather large difference I think you will agree. By
the same token I appreciate that your motive was to show how to use the code to
write patterns by showing how the B000 "code blocks" relate to the
LED positions within the actual cube. I agree this is a helpful piece of
information and I applaud you working this out and sharing your discoveries. In
closing I would just like to say that overall you did a thorough job of
explaining the cubes construction and operation – Well done.

jtmanders (author)pedro1472014-12-17

Fair enough, I'll do it! I appreciate it!

author (author)2014-11-07

tnx I love it

hwillard (author)2014-01-29

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)hwillard2014-01-29

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)jtmanders2014-01-29

And thanks!

hwillard (author)2014-01-29

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)hwillard2014-01-29

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!!!

Tyler1406 (author)2013-12-05

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)Tyler14062013-12-08

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

gazza1233 (author)2013-10-19

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)gazza12332013-10-19

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)jtmanders2013-10-19

Oh and the code would probably work I don't really know, just very time consuming and relies on the hardware you make

Tyler1406 (author)2013-06-19

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)Tyler14062013-06-20

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.

SuperTech-IT (author)jtmanders2013-08-19

If you want any help with that, let me know. I am the one that wrote the 8X8X8 cube revisited instructable.

Tyler1406 (author)jtmanders2013-06-20

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 !

'earl (author)2013-06-28

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.

Tyler1406 (author)2013-06-20

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 !

maewert (author)2013-06-11

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)maewert2013-06-11

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.

About This Instructable




Bio: “To invent, you need a good imagination and a pile of junk.” ― Thomas A. Edison
More by jtmanders:LEGO Desktop Power SupplyHow To Write Your Own 4x4x4 LED Cube Show For Arduino4x4x4 LED Cube Arduino
Add instructable to: