banner
Home / News / LED Cube With Arduino: Build an Arduino
News

LED Cube With Arduino: Build an Arduino

Mar 18, 2024Mar 18, 2024

Here we propose a project that will enchant you with its play of light, even more fascinating in the dark, based precisely on light-emitting diodes; to be exact, a matrix of monochromatic LEDs in three dimensions, arranged in space to form a cube.

This is something striking and at the same time simple, within the reach of even the youngest and those who are getting into electronics for the first time; add to this the fact that no printed circuit board needs to be built for its realization, since the connections of the cube structure are made by soldering the LED terminals together, and the terminal connections, to the controller unit, can be set up through a matrix prototyping board.

The structure of the cube consists of four levels (layers) of light-emitting diodes soldered together after appropriately bending their leads and arranging them with the proper polarity. Each level is made up of 4 rows, which in turn consist of 4 LEDs, with a total of 16 LEDs per layer; thus the cube consists of 64 LEDs in total. This is all managed by an Arduino Nano board through connections made using wires which carry the power and are soldered to a multi-holed matrix board. The firmware determines which LEDs in the cube will light up and which will not, creating lighting effects by driving them in multiplex.Our LED cube project then needs the following elements:

We will load into the Arduino board a firmware that we specially wrote and then made available to you at the bottom of this page.Electrically, the connection diagram is shown in Figure 1, which indicates the correspondence between the lines of the Arduino Nano and the rows of LEDs. More precisely, row and number of LEDs are indicated in parentheses: for example, (1, 2) means that the corresponding Arduino pin should be connected to the second LED of row 1; that is why in the diagram such pairs of numbers are indicated as Y, X.

Instead, the layers of 16 LEDs each correspond to Z and are to be connected to pins A0 (A), A1 (B), A2 (C) and A3 (D). The Z designation is more than appropriate because the layers are arranged vertically, thus, precisely, on the Z axis, while X and Y are the width and depth of the cube, defined by column.These connections are easier to understand by looking at Figure 2, which shows the spatial arrangement of the LEDs and clarifies the connections of the pairs of numbers shown in Figure 1.

Each connection to the Arduino I/O drives an anode of the LEDs, while the cathodes are joined between the diodes of each plane and go to lines A, B, C, D, which will be cycled to logic low. So, as far as hardware is concerned, each column of our cube is connected to an I/O pad on the board, so that each pin has 4 LEDs connected to it; but since our Arduino Nano has only 14 digital pins we will have to convert 2 analog pins to digital pins, so that we will get 16 digital pins (13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, A5, A4) that will allow us to turn on or off the column we want.

We applied the same procedure to the 4 levels, to which we connected 4 pins (A3, A2, A1, and A0): each pin controls one level, so that by combining the selection (turning-on) of a specific level (layer) with the selection of a specific column among the above-mentioned 16, we will be able to tell Arduino which LED to turn on and which to leave off. Using this gimmick we will be able to realize this project with only 20 I/O pins, which would have been impossible if we had connected a LED to each pin, since in that case we would have needed 64 pins and, clearly, those of a small Arduino Nano would not have been enough.To summarize, to independently control each LED, we divide the cube into levels (horizontal) and columns (vertical). Each LED placed on the same level (floor) will have the cathode (-) in common with the other LEDs on the same level while, instead, each LED placed in the same column will have the anode (+) in common with the other LEDs in the same column.In all, there will be 4 pins to control, which will be used to select the plane to be powered and 16 anodes that will power the individual columns. When we need to turn on a particular LED we will have to make sure that its plane is brought to logical zero and that the column to which it belongs is active, that is, brought to logical one.

Well, having come to this point, we can explain how to make our LED cube, an operation for which, beside the 64 light-emitting diodes (in our case, round LEDs with a diameter of 5 mm were adopted) and Arduino Nano, you will need some 0.5÷0.8 sq. mm rigid copper wire and flexible cable for the connections to the cube and between the LEDs that make it up.We also recommend that you use a square of cardboard (or of faesite or masonite of small thickness, such as 3 mm) measuring 13×13 cm that will serve as a matrix or template, which you will need to build the levels of your cube; basically you will mark this cardboard with four vertical lines and as many horizontal lines, then making four equidistant dots for each line so that at the end there will be 16 dots, each equidistant from the one next to it.You will then pierce the cardboard with the tip of the pen, just enough to fit one LED upside down, resulting in Figure 3; then to make the planes that will then form the cube, each of which is composed of 16 LEDs (in a 4×4 matrix) that will be arranged equidistant from each other, pierce the cardboard at the intersections between the rows to maintain the correct distance within the structure.

In our case, the distance (spacing) between each LED and the one next to it is 3 cm: a distance that, we feel, is the optimum to achieve a compact and functional display of the figures formed by the cube in the dark.So take the square of perforated cardboard and insert as many LEDs into the 16 holes, upside down (i.e., with the “head” in the holes), at which point you can bend the terminals and start soldering the component ones together in a plane; this template not only allows you to set a precise distance between the LEDs, but also to hold the light-emitting diodes in place to facilitate soldering. Then bend the cathodes at right angles and tin them together: for this purpose, bend them so that the one from one LED can touch the one from the next and be tinned to it. If the terminals are not long enough, connect the cathodes of each line with a piece of stiff copper wire and then crosswise, join the lines of each plane with the usual wire until a grid is made. Instead, the anodes should be bent at a step, that is, once at a right angle and then again at a 90° angle at a distance of about 3 mm, just enough so that they can pass to the side of the head of the LEDs below. Then they must be joined (if their length is not sufficient, with stiff copper wire) to those in the next layer.When you have completed one plane, take it out of the cardboard template and wire another similarly; once you have reproduced these planes in the same way, you will have to connect them vertically, through the anodes, to create a sort of cage that will support the structure, making it strong and allowing it to acquire a cube-like shape. The vertical connection will have to be one for each column of LEDs and one for each of the 16 LEDs on each floor; in fact, there are 16 columns in all (the first LED on each floor will have to match the one on the floor below and so on).To assemble the whole thing and connect it, it is advisable to use a matrix board of the right size: at least 10×10 mm; in its holes insert the ends of the columns of the cube, 16 in all, tinning them in the corresponding pads, then connect them with pieces of copper wire in sheathing, to the pads of the Arduino Nano board according to what has already been explained and referring to the indications in Figure 1 and Figure 2. A more detailed view of the assembly and connections is offered in the wiring diagram of Figure 4.

When the work is completed, you will get something like that shown in the prototype photos in this article. As you’ll see, high-brightness diodes in a transparent package have been used; if you wish to have a more uniform, albeit less intense, light emission, you can use conventional LEDs (which typically emit at an angle of 120÷140 degrees) with the colored casing: for example, the green ones proposed in Figure 2, again 5 mm in diameter.Mind that the entire circuit works with power drawn from the micro-USB connection of the Arduino Nano board, which you will connect to a computer or, once the sketch is loaded, to a power supply with a micro-USB connection, capable of delivering at least 500 milliamperes.

The code we have come up with is based on the principle of operation already stated, i.e., considering that Arduino must control four pins that will be used to select the layer to be powered and 16 anodes that will power the individual columns. When we need to turn on a given LED of the three-dimensional matrix that makes up the cube, we will have to make sure that its layer (i.e., the one on which it is physically and electrically...) is powered (i.e., its cathodes are grounded from the Arduino Nano line between A, B, C, D) and that its column is active; by doing so we will turn on one LED at a time for each level.The first thing we accomplished was to declare the pins (basically in the listing we wrote down the I/O pins that we will need in this project). Declaring pins within the code is used to configure a particular pin on the Arduino and determines whether it should be as an INPUT or OUTPUT line.In this case, the declared pins have been divided into columns (Columns) and levels (Layers), which are active outputs at logic high and logic zero, respectively (Listing 1).

Then follows the setup, in which the firmware settings are defined and the for loop, which is the basis for the display of the light effects because it defines the alternation of logic levels on the pins of the Arduino board, to controlling the LEDs in multiplex. Finally, in the sketch is the loop, which contains all the routines regarding the intended light games (refer to Listing 2).

Within this loop are the individual functions corresponding to the light games, of which we report in Listing 3 the Propeller light composition (animation), the visual effect of which is to turn on the LEDs of the planes in sequence so that a rotating light appears like the movement of a propeller.

Clearly, the functions contained in the loop are one for each of the light effects.The list of functions, or animations provided by the LED cube, is as follows:

At the end of the loop, the delay(2000) instruction; imposes a delay of 2 seconds before a new sequence is executed.Of course, to install the sketch in Arduino you have to connect the Arduino Nano board (whether it is mounted in the cube circuit, is irrelevant...) then start the IDE, then from the Tools > Board menu, choose the Arduino Nano board and then open (File > Open) the sketch, and then start loading it into the Arduino by clicking the Load button.

The advantage of this LED cube project is for you to be able to configure it to your liking, adding new lighting effects, although to do this, you need to have some knowledge of “C” programming language applied to Arduino; however, don’t worry too much because even just by searching here and there on the net you will find many similar projects to count LEDs and even beyond, with the corresponding hardware complexities.To configure the sketch for adapting ours to control more light-emitting diodes, you will only need to copy and paste the code onto the board program (for the inexperienced), then you will only need to change the pin declaration within the code or change the connections of the planes and columns on Arduino. That being said, all that remains is for you to wish each other good work and have fun with your light cube.

Figure 1(Listing 1)Elettronica IN