Student project: LED Cube

Hello everyone

the summer holidays in Germany are coming to an end and some young hobbyists have used this free time to set up their own projects. 

Today, we would like to Niklas Heinzel give the opportunity to present his project in our blog. Niklas has taken on the classic LED cube and designed and programmed it completely, from the ground up:

Today I would like to introduce you to a new exciting project, which I built at home, an LED Cube in the dimensions 4x4x4.

To do this, I use:

  • 1 x Nano V3
  • 4 x NPN 2n2222 Transistors
  • 4 x 1k resistors
  • 16 x 220 • Resistances
  • 64 x blue diffuse LED's (5mm)
  • Micro USB port
  • Yellow LED (SMD)

For the construction of the LED Cube:

For all 64 LEDs, the anode (always in the same place) is bent by 90°. These are then dissipated downwards to the plus pole.
As can be seen in the image above, the cube consists of an X-Y axis and 4 layers stacked on top of each other. The lower layer is number 0 and the upper layer is number 3. Similarly, the LEDs are numbered like a three-dimensional matrix. The lower left LED is located on layer 0 (1.1). The LED above is also located on layer 1 (1.1). The right LED on layer 0 (2.1) and so on. All horizontal layers are the negative pins of the soldered LEDs.
All positive pins of the LEDs are treated as columns of this matrix cube. So we have 4 layers and 16 columns that make it 20 wires connected to the Arduino. The positive pins (layers) have 220 ohm resistors.

 

The assembly of the cube:

First, we need a moderately thick cardboard or wood. Now we drill holes in, so that a 4 x 4 cube pattern with equal distances between all holes is created.
5mm large holes (each hole is 2.4 cm away from the next (center-center)) were drilled as a template for the LEDs.
Now you need to test and prepare your LEDs. For this purpose, you can use a 3V button cell. Test all LEDs so you don't have any problems later!
If you want the light to leak from all sides of the LED, you can sprinkle the light with sandpaper by rubbing the plastic shell.
Place the LEDs in the box, but make sure that they are aligned. The positive pins of the LEDs must be bent and the negative ones must be connected like a layer. That's because we're going to make four of these layers and it's easy to solder them together.

We repeat these layers 4x and place them on top of each other, connecting all + pins and putting them on top of each other.

 

The board, pinout and connections:

in my case, I chose the following pinout to control the cube as in a matrix:

You should make these connections and also pay attention to the correct choice of pins, otherwise the animation will not run correctly later.

I designed the board as follows and should give you only an idea of what the layout might look like:

Download link board

 

Only the code is missing:

 

LED Cube 1.0
Niklas Heinzel
//2019   Int Layer[4]={A3,A2,A1,A0}; initializing and endeclaring led layers   Int column[16]={13,12,11,10,9,8,7,6,5,4,3,2,1,0,A5,A4}; initializing and declaring led rows   Int Time = 250;



Void Setup()
{   for(Int  = 0; <16; ++)   {     pinMode(column[], Output);  setting rows to ouput   }   for(Int  = 0; <4; ++)   {     pinMode(Layer[], Output);  setting layers to output   }   randomSeed(analogRead(10));  seeding random for random pattern
}

Void Loop()
{   turnEverythingOff();   flickerOn();   turnEverythingOn();   Delay(Time);   turnOnAndOffAllByLayerUpAndDownNotTimed();   layerstompUpAndDown();   spiralInAndOut();   turnOnAndOffAllByColumnSideways();   Delay(Time);   aroundEdgeDown();   turnEverythingOff();   randomflicker();   randomRain();   diagonalRectangle();   goThroughAllLedsOneAtATime();   propeller();   spiralInAndOut();   flickerOff();   turnEverythingOff();   delay(2000);
}


//turn all off
void turnEverythingOff()
 {    for(int i = 0; i<16; i++)    {      digitalWrite(column[i], 1);    }    for(int i = 0; i<4; i++)    {      digitalWrite(layer[i], 0);    }
 }

//turn all on
void turnEverythingOn()
{   for(int i = 0; i<16; i++)   {     digitalWrite(column[i], 0);   }   //turning on layers   for(int i = 0; i<4; i++)   {     digitalWrite(layer[i], 1);   }
}
//turn columns off
void turnColumnsOff()
{   for(int i = 0; i<16; i++)   {     digitalWrite(column[i], 1);   }
}
//flicker on
void flickerOn()
{   int i = 150;   while(i != 0)   {     turnEverythingOn();     delay(i);     turnEverythingOff();     delay(i);     i-= 5;   }
}
//turn everything on and off by layer up and down NOT TIMED
void turnOnAndOffAllByLayerUpAndDownNotTimed()
{   int x = 75;   for(int i = 5; i != 0; i--)   {     turnEverythingOn();     for(int i = 4; i!=0; i--)     {       digitalWrite(layer[i-1], 0);       delay(x);     }     for(int i = 0; i<4; i++)     {       digitalWrite(layer[i], 1);       delay(x);     }       for(int i = 0; i<4; i++)     {       digitalWrite(layer[i], 0);       delay(x);     }     for(int i = 4; i!=0; i--)     {       digitalWrite(layer[i-1], 1);       delay(x);     }   }
}
//turn everything on and off by column sideways
void turnOnAndOffAllByColumnSideways()
{   int x = 75;   turnEverythingOff();   //turn on layers   for(int i = 0; i<4; i++)   {     digitalWrite(layer[i], 1);   }   for(int y = 0; y<3; y++)   {     //turn on 0-3     for(int i = 0; i<4; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn on 4-7     for(int i = 4; i<8; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn on 8-11     for(int i = 8; i<12; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn on 12-15     for(int i = 12; i<16; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn off 0-3     for(int i = 0; i<4; i++)     {       digitalWrite(column[i], 1);       delay(x);     }     //turn off 4-7     for(int i = 4; i<8; i++)     {       digitalWrite(column[i], 1);       delay(x);     }     //turn off 8-11     for(int i = 8; i<12; i++)     {       digitalWrite(column[i], 1);       delay(x);     }     //turn off 12-15     for(int i = 12; i<16; i++)     {       digitalWrite(column[i], 1);       delay(x);     }     //turn on 12-15     for(int i = 12; i<16; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn on 8-11     for(int i = 8; i<12; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn on 4-7     for(int i = 4; i<8; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn on 0-3     for(int i = 0; i<4; i++)     {       digitalWrite(column[i], 0);       delay(x);     }     //turn off 12-15     for(int i = 12; i<16; i++)     {       digitalWrite(column[i], 1);       delay(x);     }     //turn off 8-11     for(int i = 8; i<12; i++)     {       digitalWrite(column[i], 1);       delay(x);     }     //turn off 4-7     for(int i = 4; i<8; i++)     {       digitalWrite(column[i], 1);       delay(x);     }     //turn off 0-3     for(int i = 0; i<4; i++)     {       digitalWrite(column[i], 1);       delay(x);     }   }
}
//up and down single layer stomp
void layerstompUpAndDown()
{   int x = 75;   for(int i = 0; i<4; i++)   {     digitalWrite(layer[i], 0);   }   for(int y = 0; y<5; y++)   {     for(int count = 0; count<1; count++)     {       for(int i = 0; i<4; i++)       {         digitalWrite(layer[i], 1);         delay(x);         digitalWrite(layer[i], 0);       }       for(int i = 4; i !=0; i--)       {         digitalWrite(layer[i-1], 1);         delay(x);         digitalWrite(layer[i-1], 0);       }     }     for(int i = 0; i<4; i++)     {       digitalWrite(layer[i], 1);       delay(x);     }     for(int i = 4; i!=0; i--)     {       digitalWrite(layer[i-1], 0);       delay(x);     }   }
}
//flicker off
void flickerOff()
{   turnEverythingOn();   for(int i = 0; i!= 150; i+=5)   {     turnEverythingOff();     delay(i+50);     turnEverythingOn();     delay(i);   }
}
//around edge of the cube down
void aroundEdgeDown()
{   for(int x = 200; x != 0; x -=50)   {     turnEverythingOff();     for(int i = 4; i != 0; i--)     {       digitalWrite(layer[i-1], 1);       digitalWrite(column[5], 0);       digitalWrite(column[6], 0);       digitalWrite(column[9], 0);       digitalWrite(column[10], 0);       digitalWrite(column[0], 0);       delay(x);       digitalWrite(column[0], 1);       digitalWrite(column[4], 0);       delay(x);       digitalWrite(column[4], 1);       digitalWrite(column[8], 0);       delay(x);       digitalWrite(column[8], 1);       digitalWrite(column[12], 0);       delay(x);       digitalWrite(column[12], 1);       digitalWrite(column[13], 0);       delay(x);       digitalWrite(column[13], 1);       digitalWrite(column[15], 0);       delay(x);       digitalWrite(column[15], 1);       digitalWrite(column[14], 0);       delay(x);       digitalWrite(column[14], 1);       digitalWrite(column[11], 0);       delay(x);       digitalWrite(column[11], 1);       digitalWrite(column[7], 0);       delay(x);       digitalWrite(column[7], 1);       digitalWrite(column[3], 0);       delay(x);       digitalWrite(column[3], 1);       digitalWrite(column[2], 0);       delay(x);       digitalWrite(column[2], 1);       digitalWrite(column[1], 0);       delay(x);       digitalWrite(column[1], 1);     }   }
}
//random flicker
void randomflicker()
{   turnEverythingOff();   int x = 10;   for(int i = 0; i !=750; i+=2)   {   int randomLayer = random(0,4);   int randomColumn = random(0,16);   digitalWrite(layer[randomLayer], 1);   digitalWrite(column[randomColumn], 0);   delay(x);   digitalWrite(layer[randomLayer], 0);   digitalWrite(column[randomColumn], 1);   delay(x);   }
}
//random rain
void randomRain()
{   turnEverythingOff();   int x = 100;   for(int i = 0; i!=60; i+=2)   {     int randomColumn = random(0,16);     digitalWrite(column[randomColumn], 0);     digitalWrite(layer[0], 1);     delay(x+50);     digitalWrite(layer[0], 0);     digitalWrite(layer[1], 1);     delay(x);     digitalWrite(layer[1], 0);     digitalWrite(layer[2], 1);     delay(x);     digitalWrite(layer[2], 0);     digitalWrite(layer[3], 1);     delay(x+50);     digitalWrite(layer[3], 0);     digitalWrite(column[randomColumn], 1);   }
}
//diagonal rectangle
void diagonalRectangle()
{   int x = 350;   turnEverythingOff();   for(int count = 0; count<5; count++)   {     //top left     for(int i = 0; i<8; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[3], 1);     digitalWrite(layer[2], 1);     delay(x);     turnEverythingOff();     //middle middle     for(int i = 4; i<12; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[1], 1);     digitalWrite(layer[2], 1);     delay(x);     turnEverythingOff();     //bottom right     for(int i = 8; i<16; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[0], 1);     digitalWrite(layer[1], 1);     delay(x);     turnEverythingOff();     //bottom middle     for(int i = 4; i<12; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[0], 1);     digitalWrite(layer[1], 1);     delay(x);     turnEverythingOff();     //bottom left     for(int i = 0; i<8; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[0], 1);     digitalWrite(layer[1], 1);     delay(x);     turnEverythingOff();     //middle middle     for(int i = 4; i<12; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[1], 1);     digitalWrite(layer[2], 1);     delay(x);     turnEverythingOff();     //top right     for(int i = 8; i<16; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[2], 1);     digitalWrite(layer[3], 1);     delay(x);     turnEverythingOff();     //top middle     for(int i = 4; i<12; i++)     {       digitalWrite(column[i], 0);     }     digitalWrite(layer[2], 1);     digitalWrite(layer[3], 1);     delay(x);     turnEverythingOff();   }   //top left   for(int i = 0; i<8; i++)   {     digitalWrite(column[i], 0);   }   digitalWrite(layer[3], 1);   digitalWrite(layer[2], 1);   delay(x);   turnEverythingOff();
}
//propeller
void propeller()
{   turnEverythingOff();   int x = 90;   for(int y = 4; y>0; y--)   {     for(int i = 0; i<6; i++)     {       //turn on layer       digitalWrite(layer[y-1], 1);       //a1       turnColumnsOff();       digitalWrite(column[0], 0);       digitalWrite(column[5], 0);       digitalWrite(column[10], 0);       digitalWrite(column[15], 0);       delay(x);       //b1       turnColumnsOff();       digitalWrite(column[4], 0);       digitalWrite(column[5], 0);       digitalWrite(column[10], 0);       digitalWrite(column[11], 0);       delay(x);       //c1       turnColumnsOff();       digitalWrite(column[6], 0);       digitalWrite(column[7], 0);       digitalWrite(column[8], 0);       digitalWrite(column[9], 0);       delay(x);       //d1       turnColumnsOff();       digitalWrite(column[3], 0);       digitalWrite(column[6], 0);       digitalWrite(column[9], 0);       digitalWrite(column[12], 0);       delay(x);       //d2       turnColumnsOff();       digitalWrite(column[2], 0);       digitalWrite(column[6], 0);       digitalWrite(column[9], 0);       digitalWrite(column[13], 0);       delay(x);       //d3       turnColumnsOff();       digitalWrite(column[1], 0);       digitalWrite(column[5], 0);       digitalWrite(column[10], 0);       digitalWrite(column[14], 0);       delay(x);     }   }   //d4   turnColumnsOff();   digitalWrite(column[0], 0);   digitalWrite(column[5], 0);   digitalWrite(column[10], 0);   digitalWrite(column[15], 0);   delay(x);
}
//spiral in and out
void spiralInAndOut()
{   turnEverythingOn();   int x = 60;   for(int i = 0; i<6; i++)   {     //spiral in clockwise     digitalWrite(column[0], 1);     delay(x);     digitalWrite(column[1], 1);     delay(x);     digitalWrite(column[2], 1);     delay(x);     digitalWrite(column[3], 1);     delay(x);     digitalWrite(column[7], 1);     delay(x);     digitalWrite(column[11], 1);     delay(x);     digitalWrite(column[15], 1);     delay(x);     digitalWrite(column[14], 1);     delay(x);     digitalWrite(column[13], 1);     delay(x);     digitalWrite(column[12], 1);     delay(x);     digitalWrite(column[8], 1);     delay(x);     digitalWrite(column[4], 1);     delay(x);     digitalWrite(column[5], 1);     delay(x);     digitalWrite(column[6], 1);     delay(x);     digitalWrite(column[10], 1);     delay(x);     digitalWrite(column[9], 1);     delay(x);
//spiral out counter clockwise     digitalWrite(column[9], 0);     delay(x);     digitalWrite(column[10], 0);     delay(x);     digitalWrite(column[6], 0);     delay(x);     digitalWrite(column[5], 0);     delay(x);     digitalWrite(column[4], 0);     delay(x);     digitalWrite(column[8], 0);     delay(x);     digitalWrite(column[12], 0);     delay(x);     digitalWrite(column[13], 0);     delay(x);     digitalWrite(column[14], 0);     delay(x);     digitalWrite(column[15], 0);     delay(x);     digitalWrite(column[11], 0);     delay(x);     digitalWrite(column[7], 0);     delay(x);     digitalWrite(column[3], 0);     delay(x);     digitalWrite(column[2], 0);     delay(x);     digitalWrite(column[1], 0);     delay(x);     digitalWrite(column[0], 0);     delay(x);
//spiral in counter clock wise     digitalWrite(column[0], 1);     delay(x);     digitalWrite(column[4], 1);     delay(x);     digitalWrite(column[8], 1);     delay(x);     digitalWrite(column[12], 1);     delay(x);     digitalWrite(column[13], 1);     delay(x);     digitalWrite(column[14], 1);     delay(x);     digitalWrite(column[15], 1);     delay(x);     digitalWrite(column[11], 1);     delay(x);     digitalWrite(column[7], 1);     delay(x);     digitalWrite(column[3], 1);     delay(x);     digitalWrite(column[2], 1);     delay(x);     digitalWrite(column[1], 1);     delay(x);     digitalWrite(column[5], 1);     delay(x);     digitalWrite(column[9], 1);     delay(x);     digitalWrite(column[10], 1);     delay(x);     digitalWrite(column[6], 1);     delay(x);
//spiral out clock wise     digitalWrite(column[6], 0);     delay(x);     digitalWrite(column[10], 0);     delay(x);     digitalWrite(column[9], 0);     delay(x);     digitalWrite(column[5], 0);     delay(x);     digitalWrite(column[1], 0);     delay(x);     digitalWrite(column[2], 0);     delay(x);     digitalWrite(column[3], 0);     delay(x);     digitalWrite(column[7], 0);     delay(x);     digitalWrite(column[11], 0);     delay(x);     digitalWrite(column[15], 0);     delay(x);     digitalWrite(column[14], 0);     delay(x);     digitalWrite(column[13], 0);     delay(x);     digitalWrite(column[12], 0);     delay(x);     digitalWrite(column[8], 0);     delay(x);     digitalWrite(column[4], 0);     delay(x);     digitalWrite(column[0], 0);     delay(x);   }
}
//go through all leds one at a time
void goThroughAllLedsOneAtATime()
{   int x = 15;   turnEverythingOff();   for(int y = 0; y<5; y++)   {     //0-3     for(int count = 4; count != 0; count--)     {       digitalWrite(layer[count-1], 1);       for(int i = 0; i<4; i++)       {         digitalWrite(column[i], 0);         delay(x);         digitalWrite(column[i], 1);         delay(x);       }     digitalWrite(layer[count-1], 0);     }     //4-7     for(int count = 0; count < 4; count++)     {       digitalWrite(layer[count], 1);       for(int i = 4; i<8; i++)       {         digitalWrite(column[i], 0);         delay(x);         digitalWrite(column[i], 1);         delay(x);       }     digitalWrite(layer[count], 0);     }     //8-11     for(int count = 4; count != 0; count--)     {       digitalWrite(layer[count-1], 1);       for(int i = 8; i<12; i++)       {         digitalWrite(column[i], 0);         delay(x);         digitalWrite(column[i], 1);         delay(x);       }     digitalWrite(layer[count-1], 0);     }     //12-15     for(int count = 0; count < 4; count++)     {       digitalWrite(layer[count], 1);       for(Int  = 12; <16; ++)       {         digitalWrite(column[], 0);         Delay(X);         digitalWrite(column[], 1);         Delay(X);       }     digitalWrite(Layer[Count], 0);     }   }
}

 

Once the code has been uploaded, you can admire and supplement the animations.

For arduinoProjects for beginners

4 comments

Niklas Heinzel

Niklas Heinzel

Die Platine kann bei mir erworben werden. Bei Interesse bitte an niklas-heinzel@gmx.de.

Niklas Heinzel

Niklas Heinzel

Die Platine kann erworben werden. Bei Interesse bitte an niklas-heinzel@gmx.de.

AxelF

AxelF

Kann man die Platine, wie abgebildet, käuflich erwerben?
Ich kann sie nämlich nicht herunterladen.

Andreas K.

Andreas K.

Hm… wie ist das mit der maximalen Strombelastung?
Ab 40mA pro Ausgangs-Pin bzw. 200mA in Summe auf allen Ausgangs-Pins (geht durch Masse bzw VCC) wird es beim 328 irgendwann kritisch.
Wenn alle LEDs leuchten, kommen mit den 220 Ohm Widerständens schon mal 300mA oder mehr zusammen, die dann insgesamt durch die Massepins fließen.
Wie lange macht der MC das mit?

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN