# Simple 3x3x3 LED Cube

1,537

16

4

## Introduction: Simple 3x3x3 LED Cube

I decided I wanted to make an LED cube, but I couldn't find any simple instructables. Most of the 3x3x3 LED cubes I found used transistors or different microcontrollers and I honestly didn't understand how most of them worked, so I made this one which uses nothing but LED's, resistors, and an Arduino. The code does end up being pretty long but I think overall, the idea is simpler. Hopefully this instructable is clear and you will be able to follow and make your own LED cube.

Materials:

• 27 LED's (whatever color you choose)
• 9 330 Ohm resistors
• Wire
• Soldering iron and solder
• Cardboard
• Arduino and Arduino program
• Perfboard(optional)

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Cube Pt. 1

First, you will need a piece of cardboard with 9 holes as shown above. Place 9 LED's into the nine holes so that their negative leads(the shorter lead on the flat side of the LED) are all facing the outside of the square and bend them down so that they are all touching. Solder all of the leads together and remove the LED's from the cardboard to make one level of the cube. Repeat three times. Each level of LED's should have all of the negative leads soldered together with the positive leads sticking downwards.

## Step 2: Cube Pt. 2

Now you will need to stack all three layers and solder their positive leads together. You may need to bend the leads inwards and play around with it to get each layer's leads to touch. When you're done, you should have every LED's negative lead connected to the negative leads of all of the other LED's in its layer while every LED's positive lead is connected to the positive leads of all of the other LED's in its column. Make sure that no positive leads cross with negative leads or you could get a short circuit.

## Step 3: Testing

When you are done, it is a good time to test your connections by connecting a power source's positive to each column and it's negative to each level to make sure each LED turns on when it should. The idea is each LED should turn on when it's column has power and it's level is grounded. I used a 9V battery and a resistor to test it. A resistor is important if you are testing it with a voltage above 3V so that that the LED doesn't burn out. If an LED doesn't light up when it should, it could mean a bad connection, short circuit, or even a burnt out LED.

## Step 4: Wiring

Now you need to wire the cube to the Arduino. I used a piece of perfboard and soldered the cube to it to help keep the wiring organized, but you could just as easily use a breadboard. I connected a 330 ohm resistor to each column and then to a pin (2-10) and I then connected each level to a pin (11-13). Once again the resistors are important to make sure the LED's don't burn out.

I connected the columns to pins like so:

10 7 4 2

9 6 3 1

8 5 2 0

2 1 0

(This is from the top view, the bold numbers represent the pin numbers)

This made the programming easier because you could use (3*x)+y+2 to find the pin number, x being the x-coordinate (starting at 0 from the right) and y being the y-coordinate (starting at 0 from the bottom). The x-values and y-values are shown by the non-bold numbers above.

## Step 5: Programming

For the programming, you can do a lot of different patterns, but basically to turn on an LED, you need to set its column's pin to HIGH and it's layer's pin to LOW. This causes current to flow through the column pin, through the LED, and back to the Arduino through the layer pin. Another thing to note: if you want to turn on multiple LED's at once, it may light up other LED's that you didn't intend to light up, so you would need to flash them separately so quickly that it looks like they are on at the same time. An example of this is if you wanted to light up pin 2 in the top layer and pin 3 in the middle layer, pin 2 in the middle layer and pin 3 in the top layer would also turn on because their column pins would be set to HIGH and their layer pins would be set to LOW.

Here is my code:

```void setup() {
for (int i = 2; i <= 13; i++)
pinMode(i, OUTPUT);
for (int i = 11; i <=13; i++)
digitalWrite(i, HIGH);
}```
```void loop() {
int del = 100;

//flashes LED's from top to bottom
for (int i = 0; i <= 3; i++)
{
for (int i = 0; i <= 10; i++)
digitalWrite(i, HIGH);
for (int i = 11; i <= 13; i++)
{
digitalWrite(i, LOW);
delay(del);
}
for (int i = 11; i <= 13; i++)
{
digitalWrite(i, HIGH);
delay(del);
}
}
//flashes LED's in a downwards spiral
for (int i = 0; i <= 10; i++)
digitalWrite(i, LOW);
for (int i = 0; i < 3; i++)
{
flash(del, 0, 0, i);
flash(del, 1, 0, i);
flash(del, 2, 0, i);
flash(del, 2, 1, i);
flash(del, 2, 2, i);
flash(del, 1, 2, i);
flash(del, 0, 2, i);
flash(del, 0, 1, i);
}
//flashes LED's in one random column from top to bottom
for (int i = 0; i <= 9; i++)
{
int x = random(3);
int y = random(3);

for (int i = 0; i <= 2; i++)
{
flash(del+50, x, y, i);
}
delay(del);
}
//randomly flashes LED's
for (int i = 0; i <= 200; i++)
{
int x = random(3);
int y = random(3);
int z = random(3);
flash(10, x, y, z);
}
//flashes LED's from one corner outwards
for (int i = 0; i <= 3; i++)
{
flash(2*del, 0, 0, 0);
for (int i = 2*(del/7); i >= 0; i--)
{
flash(1, 0, 1, 0);
flash(1, 1, 1, 0);
flash(1, 1, 0, 0);
flash(1, 0, 0, 1);
flash(1, 0, 1, 1);
flash(1, 1, 1, 1);
flash(1, 1, 0, 1);
}
for (int i = 2*(del/19); i >= 0; i--)
{
flash(1, 0, 2, 0);
flash(1, 1, 2, 0);
flash(1, 2, 2, 0);
flash(1, 2, 1, 0);
flash(1, 2, 0, 0);
flash(1, 0, 2, 1);
flash(1, 1, 2, 1);
flash(1, 2, 2, 1);
flash(1, 2, 1, 1);
flash(1, 2, 0, 1);
flash(1, 0, 0, 2);
flash(1, 0, 1, 2);
flash(1, 0, 2, 2);
flash(1, 1, 0, 2);
flash(1, 1, 1, 2);
flash(1, 1, 2, 2);
flash(1, 2, 0, 2);
flash(1, 2, 1, 2);
flash(1, 2, 2, 2);
}
}
}
void onOff(boolean state, int x, int y, int z) {  //turns on or off led at (x, y, z)
if (state)
{
digitalWrite(z+11, LOW);
digitalWrite((3*x)+y+2, HIGH);
}
else
{
digitalWrite(z+11, HIGH);
digitalWrite((3*x)+y+2, LOW);
}
}
void flash(int msec, int x, int y, int z) {  //flashes led at (x, y, z) on and off for msec
onOff(true, x, y, z);                      //milliseconds
delay(msec);
onOff(false, x, y, z);
}
```

Your code could vary depending on your wiring and how you want the LED cube to act, but this might give you an idea about what it could look like. Hopefully, your LED cube is working and if you have any questions, leave them in the comments.

175 14K
223 30K
112 10K

## 4 Discussions

Hi, I made the Radio Shack 3D LED Cube Kit, and unfortunately their link to the code was defunct. However, I uploaded your code, and it works great! Thanks!

Awesome! I'm glad this could help.

Thanks!