### 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}; void setup() // 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);   } } void loop() // 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 LEDs   delay(1000); // delays for 1000ms   input();         // sets all LEDs as inputs   delay(500); // delays for 500ms   all();           //turns on all the LEDs   delay(1000); // delays for 1000ms   input();         // sets all LEDs as inputs   delay(500); // delays for 500ms   all();           //turns on all the LEDs   delay(1000); // delays for 1000ms   input();         // sets all LEDs as inputs   layerone();      // turns on layer one of LEDs   delay(1000); // delays for 1000ms   input();         // sets all LEDs as inputs   layertwo();      // turns on layer two of LEDs   delay(1000); // delays for 1000ms   input();         // sets all LEDs as inputs   layerthree();    // turns on layer three of LEDs   delay(1000); // delays for 1000ms   input();         // sets all LEDs as inputs   layerfour();     // turns on layer four of LEDs   delay(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 LEDs   delay(1000); // delays for 1000ms   layerone();       // turns on layer one of LEDs   delay(1000); // delays for 1000ms   layertwo();       // turns on layer two of LEDs   delay(1000); // delays for 1000ms   layerthree();     // turns on layer three of LEDs   delay(1000); // delays for 1000ms   layerfour();      // turns on layer four of LEDs   delay(1000); // delays for 1000ms   input();          // sets all LEDs as inputs   all();            //turns on all the LEDs   delay(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 output     pinMode(neg[i], OUTPUT); // sets negative i as output     digitalWrite (pos[i], HIGH); // turns positive i on     digitalWrite (neg[i], LOW); // turns negative i on     delay(pace); // delays for pace     pinMode(pos[i], INPUT); // sets positive i as input     pinMode(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 output     pinMode(10, OUTPUT); // sets pin 10 as output     digitalWrite (pos[i], HIGH); // turns positive i on     digitalWrite (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 output     pinMode(11, OUTPUT); // sets pin 11 as output     digitalWrite(pos[i], HIGH); // turns positive i on     digitalWrite(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 output     pinMode(12, OUTPUT); // sets pin 12 as output     digitalWrite(pos[i], HIGH); // turns positive i on     digitalWrite(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 output     pinMode(13, OUTPUT); // sets pin 13 as output     digitalWrite(pos[i], HIGH); // turns positive i on     digitalWrite(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 output     pinMode(neg[i], OUTPUT); // sets negative i as output     digitalWrite(pos[i], HIGH); // turns positive i on     digitalWrite(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.

Comments