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 extra IC, purely with the available on-board pins. for further inquiry please go to our technical forum as we seldom check the comment section of tutorial.
330 Ohm resistors x16 Donut board 3.7V batteries x2
Battery holder DC Jack Slide Switch
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 as there will be extra LEDs in case anything goes wrong.
You also need to have good soldering skill. If you are newbie in soldering, try to get use with it before you can start to solder the cube.
Before start developing the cube, there are some terminologies on the words that will be use 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 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, 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 drawn 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.
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.
Solder and trim the extra portion of legs.
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 arrived at the last step in constructing an LED cube, connect all pin header 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:
(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.
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 callingcubeClear();
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.