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):
UPDATE:
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.
NOTE:
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.
Attachments
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:
B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
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 3....pictures 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:
B0001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
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!
B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
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
B0001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
Turn on row 1:
Photo 2
B1111,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
Turn on all four corners:
Photo 3
B1001,B0000,B0000,B1001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B1001,B0000,B0000,B1001,10
Turn on all of layer 1:
Photo 4
B1111,B1111,B1111,B11111,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,
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.

Participated in the
Arduino Contest
45 Comments
7 years ago
sir
exit status 1
'prog_uchar' does not name a type
errro
sollution this program
Reply 2 years ago
Before was "prog_uchar", now is "const unsigned".
7 years ago
Sir, I am having a problem with your code, it says
prog_uchar does not name a type
Reply 2 years ago
Before was "prog_uchar", now is "const unsigned".
Reply 3 years ago
yes i face the same error
5 years ago
Circuit diagram show
6 years ago
Plz send program document led cube klkeshava@gmail.com
6 years ago
Pls send program document led cube
8 years ago on Step 2
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!
Reply 8 years ago
Change that line to this
const int PatternTable[] PROGMEM = {
Reply 7 years ago
Yes, but when you do that it doesn't upload.
Reply 7 years ago
Worked for me 9 months ago. Things might have changed.
7 years ago
Will the program work with audrino mega
7 years ago
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
8 years ago on Introduction
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?
8 years ago on Introduction
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 (https://www.instructables.com/id/4x4x4-LED-Cube-Arduino-Uno/?ALLSTEPS)
It's probably a stupid question, but how do i alter your code to make it match my cube?
Thanks in advance.
Reply 8 years ago on Introduction
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.
Reply 8 years ago on Introduction
Wow, thanks! I will definitely try that.
Reply 8 years ago on Introduction
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!
8 years ago
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.
thanks...