LED Cube

Keaton Zonca and Cecilia DeBoever

4 x 4 x 4 LED Cube

This project is a simple LED cube. We soldered together 64 LEDs in order to create this. The LEDs can be programmed to light up in various ways. We have currently programmed it so the lights can all be one at one time or they can light up one by one in order.

YouTube Video

http://www.youtube.com/watch?v=2sX-azgzyIg

// This program controls our 4x4x4 LED cube. It first cycles through all the LEDs, repeats it faster, flashes all the LEDs, goes laye
by layer, cycles through them again, and flashes one last time before repeating.
int pos[] = {
16,17,18,19,1,0,14,15,5,4,3,
2,9,8,7,6,16,17,18,19,1,0,14,
15,5,4,3,2,9,8,7,6,16,17,18,
19,1,0,14,15,5,4,3,2,9,8,7,6,
16,17,18,19,1,0,14,15,5,4,3,2,9,8,7,6};
int neg[] = {
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13};
voidsetup() // run once, when the sketch starts
{
for(int i=0; i<64; i++) //sets all 64 LEDs as inputs
{
pinMode(pos[i], INPUT);
pinMode(neg[i], INPUT);
}
}
voidloop() // run over and over again
{
sequence(300); //cycles through all the LEDs at pace 300
sequence(100); //cycles through all the LEDs at pace 100
all(); //turns on all the LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputsdelay(500); // delays for 500ms
all(); //turns on all the LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputsdelay(500); // delays for 500ms
all(); //turns on all the LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputs
layerone(); // turns on layer one of LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputs
layertwo(); // turns on layer two of LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputs
layerthree(); // turns on layer three of LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputs
layerfour(); // turns on layer four of LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputs
sequence(100); //cycles through all the LEDs at pace 100
all(); //turns on all the LEDsdelay(1000); // delays for 1000ms
layerone(); // turns on layer one of LEDsdelay(1000); // delays for 1000ms
layertwo(); // turns on layer two of LEDsdelay(1000); // delays for 1000ms
layerthree(); // turns on layer three of LEDsdelay(1000); // delays for 1000ms
layerfour(); // turns on layer four of LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputs
all(); //turns on all the LEDsdelay(1000); // delays for 1000ms
input(); // sets all LEDs as inputs
}
void sequence(int pace) //cycles through all the LEDs at pace
{
for(int i=0; i<64; i++) // declares i and test if less than 64, and then does the following
{
pinMode(pos[i], OUTPUT); // sets positive i as outputpinMode(neg[i], OUTPUT); // sets negative i as outputdigitalWrite (pos[i], HIGH); // turns positive i ondigitalWrite (neg[i], LOW); // turns negative i ondelay(pace); // delays for pacepinMode(pos[i], INPUT); // sets positive i as inputpinMode(neg[i], INPUT); // sets negative i as input
}
}
void input() // sets all LEDs as inputs
{
for(int i=0; i<64; i++) //sets all 64 LEDs as inputs
{
pinMode(pos[i], INPUT);
pinMode(neg[i], INPUT);
}
}
void layerone() // turns on layer one of LEDs
{
for(int i=0; i<16; i++) // declares i and test if less than 16, and then does the following
{
pinMode(pos[i], OUTPUT); // sets positive i as outputpinMode(10, OUTPUT); // sets pin 10 as outputdigitalWrite (pos[i], HIGH); // turns positive i ondigitalWrite (10, LOW); // turns pin 10 on
}
}
void layertwo() // turns on layer two of LEDs
{
for(int i=0; i<64; i++) // declares i and test if less than 64, and then does the following
{
pinMode(pos[i], OUTPUT); // sets positive i as outputpinMode(11, OUTPUT); // sets pin 11 as outputdigitalWrite(pos[i], HIGH); // turns positive i ondigitalWrite(11, LOW); // turns pin 11 on
}
}
void layerthree() // turns on layer three of LEDs
{
for(int i=0; i<64; i++) // declares i and test if less than 64, and then does the following
{
pinMode(pos[i], OUTPUT); // sets positive i as outputpinMode(12, OUTPUT); // sets pin 12 as outputdigitalWrite(pos[i], HIGH); // turns positive i ondigitalWrite(12, LOW); // turns pin 12 on
}
}
void layerfour() // turns on layer four of LEDs
{
for(int i=0; i<64; i++) // declares i and test if less than 64, and then does the following
{
pinMode(pos[i], OUTPUT); // sets positive i as outputpinMode(13, OUTPUT); // sets pin 13 as outputdigitalWrite(pos[i], HIGH); // turns positive i ondigitalWrite(13, LOW); // turns pin 13 on
}
}
void all() //turns on all the LEDs
{
for(int i=0; i<64; i++) // declares i and test if less than 64, and then does the following
{
pinMode(pos[i], OUTPUT); // sets positive i as outputpinMode(neg[i], OUTPUT); // sets negative i as outputdigitalWrite(pos[i], HIGH); // turns positive i ondigitalWrite(neg[i], LOW); // turns negative i on
}
}

We were able to control each individual LED by using arrays. We connected the negative ends of each LED in a layer together and the positives of each column together. Each column and layer was connected to a pin on our Arduino. We could then light up whichever LED we wanted by making the positive high for the column we wanted and the negative low for the layer it was on. We could then program different patterns depending on what LEDs we wanted lit up. The program either cycles through all the LEDs or turns them all on depending on what positive and negatives have power at what time. To make it easier to control which LEDs we wanted, we set up for loops that will simply cycle through the LEDs instead of having to turn each one on individually in the code. We also used variables so that we could change the speed of the cycling LEDs with a simple change of one number. The code is a simple way to be able to control more LEDs than you have pins for on an Arduino board.

We encountered a few problems throughout this entire project and we were able to overcome most of them. One of our first problems was we were unable to upload anything to our arduino. The reason for this problem was because we had things plugged into the pins 0 and 1, and you cannot have that while uploading. We fixed our problem by simply unplugging those wires and plugging them back in after uploading. We had a problem with our cube falling apart a lot. This was fixed by additional soldering and making the cube stronger. At one point we had broken our arduino. Not sure how that happened, but we took everything apart, got a new arduino, and set it up again. It worked fine once we got a new one. One big problem we encountered while putting the final project together was the size of our arduino shield. In order to make this all fit inside our box, we had to cut down our shield. We sawed part of the board off and it fit perfectly. One final problem we encountered was one we were unable to fix. One column of our cube always has an LED lit up. We are not entirely sure of the source of the problem, so we cannot fix it.

If we had more time we would have liked to make our cube react to sound. It would be cool and interesting to see the lights react according to music played. We did not have enough time to figure out how to do this and make it work properly. If we had more money, something we would have been interested in doing would be to use multicolored LEDs. These are very pricy in comparison to the ones we used, but they are very cool looking. They also would have been more complicated and would require more time to figure out.