As we all know, an LED Cube is a bunch of LED that arranged in a cube shape that can perform some interesting lighting effects according to your program. In this tutorial, we are going to learn how to construct a 4x4x4 LED Cube using Arduino UNO board without any extra IC, solely with the available on-board pins. for further inquiries please go to our technical forum as we seldom check the comment section of tutorial.
Arduino IDE – an open source Integrated Development Environment used to program Arduino board. You can download it here.
P/S: Actually, we only need 64 of LEDs. I stated 70 LEDs so there will be extra LEDs in case anything goes wrong.
You also need to have good soldering skills. If you are a newbie in soldering, try to get used to it before you can start to soldering the cube.
Before we start developing the cube, there are some terminologies on the words that will be used in this tutorial.
Refer to the image below:
- LAYER(black color line in picture)
- The cathode (negative/shorter) legs are all connected in the same horizontal plane.
- LINE (red color line in picture)
- The anode (positive/longer) legs are all connected in same vertical position.
(Click the image for larger view and please do not complain my drawing, I tried my best =.=|||)
Now, let’s give each line and layer a name so that we can easily find it.
From the picture above, there are 3 axes namely x,y, and z.
- xy-plane represent the layout of horizontal layer
- z-axis represent the vertical height of layers.
The table below show the representation of XYZ coordinates.
|xy||line at the top left|
|xy||line at the top right|
|xy||line at the bottom left|
|xy||line at the bottom right|
|xyz||particular LED(bottom right line, top layer.)|
The circuit will looks a little bit complicated, so I have attached the Fritzing file along with the source code in case you want to have a better looks. You can download it at the attachment below.
Alright, the very first step in developing an LED cube is to make sure that every LED is working (not joking, every!). You can test it using a 3V cell battery, as shown in pictures at the left. Make sure to check the polarities of cell battery first, or else your LED won’t work.
Next, to get a nice cube shape, we need to do something to the LED legs. Bend the anode leg of LED as shown.
After that, bend the cathode leg to 90° as shown. You can bend to any direction, but just be sure that the direction is consistent. If you are not sure where to bend, just follow my direction.
Alright, finish with LED. Now we want something that can help us hold the LEDs while we solder, and keep all LEDs in shape.
Get a box or anything else that you could pokes a hole on it, draw something like the picture shown at the left. The distance between each nodes would be approximately 2.5cm (the length of LED cathode leg).
(Click the image for larger view)
Notice I drew a dashed rectangle portion there, we will get to it in next step.
Poke all 16 nodes on the holder, and place LED on it. Arrange your LEDs as the arrow indicated, black arrow represents the cathode, red arrow represents the anode.
After the arrangement, you will see that there is no leg connection inside the dashed portion, this is not a problem, as we already connected all cathode legs.
(Click the image for larger view)
Now, get your solder gun ready, solder the negative legs that touching each other so that all cathodes are connected as a layer.
Out of obsession, I soldered a lead pin to the dashed region to make the layer more comfortable to look at.
Then, take some rest, and start another one. Repeat this step until you have 4 layers =P.
So, finished with all 4 layers? Then, combine layer with layer, it is very hard to do it alone, so you have to find a friend (or victim? :-P) to help you hold both layers together while you do the soldering. A reminder to your friend, it gets really hot…
After finish stacking all 4 layers, mount your cube on a donut board, and bend the LED legs to fix it.
Next, putting resistors and pin headers on the board as shown, and solder each resistor to one pin. Trim the extra portion of resistor’s leg.
Solder each LED leg to corresponding resistor, take extra care on the position to avoid any confusion. The connection is soldered exactly the same as in Fritzing file, and I also clarify it in the source code too.
Add a conductor to each layer and solder it to the corresponding pin header so that we can connect to Arduino board.
I trimmed some broken LED legs for this purpose, you can just use a wire if you want.
Alright, now mounting Arduino board and battery holder on the donut board, and add a switch between them. The switch is optional, but it helps you from frequently plug and unplug the DC jack.
Finally, we have arrived at the last step in constructing an LED cube, connect all pin headers to the Arduino board using male-to-female jumper wires, make sure to connect it as shown in the Fritzing diagram, or else the code might go wrong. You can tidy up the jumper wires using a cable tie.
I am sure that someone will find suspicious here. Yes, you see it right, I am connecting my wires to Arduino analog input pin. If you want to ask why, it is because the analog pins can also act as general purpose I/O (GPIO) too. This is not something magical and it is stated in Arduino official website here. So with this feature, it allow us to control 4x4x4 LED cube using Arduino UNO board without I/O expansion IC.
In the end, your cube should looks something like this:
So we have successfully built an LED cube, the next thing is to understand how the cube works.
Suppose we want the LED at xyz light up as the image below. What we need to do is just apply HIGH to the pin at xy, and LOW to the pin at z, simple and understandable.
Now, what if I want the LED at xyz to light up too? You might think just simply apply HIGH to the pin at xy and LOW the z. However, the result will looks like this:
You will notice xyz, and xyz also lighted up.
(P/S: Layer1 is not lighted up, it is purely the reflection from layer0)
Why? This is because when you turn on xyz, line xy is still HIGH. So when you turn z to LOW, the circuit for xyz is also completed thus it will light up. The same case also apply to xyz. Since z is originally LOW, applying HIGH to line xy will turn it on too.
Does it have a solution? Of course. A method called multiplexing is quite simple. Just repeatedly turning on one LED while the others are off, then reverse the situation quickly, and ta-daa!! 🙂 :
(P/S: layer1 is not lighted up, it is purely the reflection from layer0)
Again, this is not something magical. It is just the Arduino board switches between these two LEDs faster than human eyes could detect, thus creating an optical illusion of two LEDs light up at the same time.
Now, let’s see the code that have been provided. There are four additional function for you to call.
I will go through it one by one.
This function is used to clear all LEDs, returning them to their default state: LOW for lines, and HIGH for layers.
It takes no parameter and return nothing, so you can just use it by calling
This function will turns on all LEDs, it takes no parameter and return nothing, so just call it by
This function will turns on one LED at any desired position, it takes two parameters and return nothing. You need to provide the position of which LED to light up when you call this function.
where xy is the line position, and z is the layer.
This function will turns off one LED at any desired position, it takes two parameters and return nothing. You need to provide the position of which LED to turn off when you call this function.
where xy is the line position, and z is the layer.
However, this function might not work as desired when multiple LEDs are in use.
So, here is part of the code that showing matrix display in the video below. I will explain how it works after this.
|line 194||Before any new pattern comes in, we must clear the whole cube|
|line 195||delay 500ms to avoid the display start immediately after the clear.|
|Line 197-201||turn on all LEDs at layer3.|
|Line 202-206||turn layer 2,1,0 LOW, one at a time, from top to bottom. Since all the lines are HIGH now, so turning the layer LOW will immediately light up all LEDs at that layer. The delay 100ms there is to create a chasing effect, and to avoid all LEDs light up at once.|
|Line 207-210||turn layer3,2,1,0 HIGH, one at a time, from top to bottom, also with chasing effect.|
|Line 211-214||create the same effect as Line 202-206, but in reverse direction (from bottom to top).|
|Line 215-218||turn layers HIGH just like Line 207-210, but in reverse direction (from bottom to top).|
These whole codes are enclosed by a big for() loop (line 196) to repeat it 3 times, and done~ All you need to do is just turning some digital pins ON and OFF, add some delay, add some loop, and that’s it.
Finally, if you have any question, feel free to ask in our technical forum as we seldom check the tutorial’s comment section.
You can download the sample source code below. Of course the pattern is not limited to the one that I show in the video, you can try with different combination of lighting patterns, take a video, and share it to our Facebook ^_^.