Introduction: 4X4X4 3D Led Cube
An LED Cube is a programmable cube of leds; in this case it is a 4X4X4 cube.
Once made, the cube can be programmed (using a micro controller) to display any pattern you like.
You can also hook the cube up to sensors to take input from the environment and then display patterns in accordance with changes detected in the environment.
Examples include -
1. Detecting sound in the environment using a microphone, and then brightening or dimming the leds as the sound intensity increases or decreases. A more sophisticated example may be to detect the dominant frequency in the sound signal received and then brighten-dim-brighten-dim the leds at this frequency.
2. We can hook up the cube to a joystick and push buttons, and then create an entire game playable on the cube, in which the input will be taken through the joystick and buttons. In this instructable, I actually make the prototype of a snake game playable on the 3D Led cube. It's a great idea, to shift the classic snake game from our 2D phones to the 3D cube, but to be properly implemented, requires a much larger cube (something like 8X8X8) and RGB leds that can also be seen through when not lit. Hence our version on the 4X4X4 cube can't really give the proper feel of a snake game, and is thus a prototype.
Step 1: Materials Required
1. Metal Base with holes in which the leds will be fitted
2. 4X4X4 = 64 leds of any colour (I used green)
3. Soldering equipment - soldering iron, wire and flux
4. Lots of jumper wires (Collect 50 to be on the safe side)
5. A 16 bit shift register or 2 X 8 bit shift registers (I used the latter as they are more easily available)
6. 1 X Arduino Uno micro controller
7. 2 X push button switches
8. 2 X 10K resistors (or any other large resistance value) (for grounding the above mentioned push button switches)
9. 1 X joystick
10. Large thermocol and cardboard pieces to act as bases ( visible in the project image)
11. 2 X breadboard
Step 2: Make the Led Cube Structure
The led cube consists of four horizontal layers of leds, with 16 leds in each layer
The cathodes (negative terminals) of all the leds in a horizontal layer are soldered together
The anodes (positive terminals) of all the leds in a vertical column are connected (soldered)
The bottom layer of the cube rests on a metal base
We thus have a total of 20 wires (1 wire for each of the 16 vertical anode lines; and 1 wire for each of the 4 horizontal layers of leds coming out from the cathode) coming out of the led cube.
To light a particular led, we supply positive voltage to the vertical anode line corresponding to that led, and negative voltage to the horizontal cathode layer corresponding to that led. To prevent the other leds along the same vertical anode line from lighting up, we need to supply positive voltage to the rest of the 3 horizontal cathode layers. This will however set up a reverse bias voltage across the concerned leds. Thus the potential difference supplied to the leds should not exceed their reverse bias limit ( I used a potential difference value of 3.3 V)
This method of connecting the leds reduces the number of wires coming out of the cube significantly from 4 X 4 X 4 X 2 = 128 to just 20. However, now trying to light up multiple leds at a time will create problems. Thus to create the effect of multiple leds being lit, we will have to rely on persistence of vision (explained later in the programming step)
Step 3: Connecting the Cube to the Shift Register
A shift register is an IC that converts serial data sent to it to parallel output data or vice-versa
Thus we can control the input sent to all of the 16 anode wires of the cube from a single port on the arduino, by sending in data serially for the 16 wires, and then getting a parallel output.
To make a 16 bit shift register from two 8 bit registers, the serial-output pin of the first shift register is connected to the serial-input pin of the second shift register
Here are 2 helpful links to learn to use shift registers with an arduino:
The 2 shift registers are mounted on a separate breadboard, and then connected to the led cube
Step 4: Connect the Shift Registers to the Arduino
By completing the previous step, we can control the 16 anode wires of the cube, from a single port on the arduino. We however still need to control the 4 cathode wires separately from the arduino.
We thus need to use 5 digital out pins of the arduino for this.
Other pins of the arduino will be used to supply power to the shift register, and also to ground it
Step 5: Program the Arduino
We now program the arduino to display the any pattern that we like.
To create the effect of multiple leds lighting up a time, we use persistence of vision. Let's say that we want to make it look like 2 leds lighting up at the same time. We first light up led 1 for a short time, then turn off led 1 and light led 2 for the same short time, then turn off led 2, and then repeat the cycle. This method can be used to make it look like any number ( say n ) of leds are lighting up at the same time.
The time for which we let each led light up in the cycle (say t) plays a crucial role here. If you increase the t value for a particular led, it will make that led look brighter than the rest (This has actually been used in my snake game implementation to make the head of the snake look brighter than the rest of the body). On the other hand, decreasing the t value will make the persistence of vision effect smoother.
The number leds (n) is also an important factor. Increasing the value of n decreases the brightness of each led being lit in the cycle.
Before writing any code, it would be a good idea to first create certain crucial functions that will be used extensively in the code:
1. Function updateShiftRegister( int a) which sends high voltage to a particular anode line out of the 16 anode lines based on the values in byte leds and byte leds.
2. Function light_led which lights up a particular led by using the function updateShiftRegister()
3. A function to light up multiple leds at a time using POV. In the snake game implementation, this function is draw_snake().
It would also be a good idea to refer to each led in the cube using a structure, that stores 2 values: the led's position on the horizontal grid (0 to 15) and the led's height (0 to 3). These parameters can then be used as input to the function light_led.
A few codes that I have written have been attached.
And here are the videos of the programs in action
Step 6: Connect Additional Input Devices, If Needed
Now you can connect input devices to the arduino, to make your led cube respond to changes in its environment; examples include microphone, light sensor, push buttons, joystick etc.
For the snake game, I have connected 2 push buttons and a joystick to the arduino. The joystick moves the snake head in a horizontal plane (forward, backward, left, right) while the push buttons move it up and down.
It is essentially a collection of 2 potentiometers, one potentiometer is used to detect joystick movement in the y direction, while the other detects movement in the x direction. When the output from the 2 potentiometers is connected to the analog input pins of the arduino, the detected voltages can be used to tell the precise displacement of the joystick from its central position
The joystick and push buttons are mounted on a separate cardboard for ease of use. The whole apparatus - arduino, led cube, breadboard with shift registers and input devices are attached to a thermocol base for ease of handling.
The project is now complete
Step 7: Possible Improvements
1.Make a bigger cube (say 8 X 8 X 8): This is easier said than done. Making the 4 X 4 X 4 cube already involved a lot of painstaking hours of soldering. This bigger cube will take 2 X 2 X 2 = 8 times more time to make than the current cube.
2. Use RGB leds: This will give the cube the ability to display 3 colours - red, green and blue. It will add a lot of functionality to the cube - for example, we can make the food for the snake a different colour from the snake's body, to make them easily distinguishable. However, it will also require 3 times more time to make
3. Make it more aesthetically pleasing: The version of the cube shown is particularly elegant to look at - it has large number of wires tangling around into each other and makes the entire circuitry visible to the user of the cube. A better approach will be to actually hide all that circuitry from the user, and only make the cube itself visible to him. The wires should also be cut down to precisely the length needed, and then bundled together to make it look more elegant.
4. Make the cube respond to sound in the environment: We could attach a microphone to the arduino and then use the signal from it to control the cube. For example - intensity of the pattern displayed on the cube, or the frequency of a repetitive cycle of patterns on the cube could be a function of the dominant frequency or intensity observed in the sound signal.
We have a be nice policy.
Please be positive and constructive.