# LED Cube

(diff) ← Version précédente | Voir la version courante (diff) | Version suivante → (diff)
LED Cube

This project is for the Digital Integrated Circuits and Microcontrollers course.

The LED Cube is a 3D cube composed of 64 LEDs (4 x 4 x 4).

# Hardware

## List of components

Given by the professor :

• Protoboard for the uC
• Atmel ATMega16PU
• Regulator 7805
• Capacitor : 5x1uF
• Capacitor SMD : 6x0.1uF
• Max232
• Diode 1N4001
• 2 LEDs (Orange & Green)
• 2 Pushbuttons
• Quartz 7,3728MHz
• 3 resistors

What we bought in supplement :

• Protoboard for the cube
• 64 Green LEDs
• 16 x 220ohm resistors (Explication later)
• 4x 2.2K resistor
• 4x NPN transistor BC639
• Ribbon cable with connectors

## Choice of components

### LED

Technical Specifications :

• Colour : Green
• WL [nm] : 565
• LI [mcd]: 19
• IF [mA] : 10
• UF [V] : 2,1

WL = Peak Emission Wavelength, LI = Typ. Luminous Intensity, IF = Forward Current, UF = Forward Voltage

### Transistor BC639

Technical specifications :

• $Ic_{max} = 0.8A$
• $Vbe = 1V$
• $Vce_{sat} = 0.5V$

The ATMega16 can drive up to 200mA max, with 20mA per pin.

Since we drive, maximum 16 LEDs, at one time, we can have 200/16 = 12,5mA per pin maximum.

To be sure, we are going to set at 12mA per LED.

So we need a transistor with a collector current of at least 200mA.

We chose the BC639 (NPN), which can go up to 800mA and because it was in stock in the electronic shop.

We calculate the resistor for the LED :

$$Rled = \frac{(Vcc - Vled - Vce_{sat})}{Ic} = \frac{(5-2.1-0.5)}{ 0.012} = 200 \Omega$$

We will take $\textbf{Rled = 220} \Omega$ since it's a standard.

We calculate the resistor for the transistor :

with $$Ib_{min} = \frac{Ic_{min}}{ gain} = \frac{0.012}{100} = 120mA$$

and $$Ib_{max} = \frac{Ibmax}{gain} = \frac{0,2}{100} = 2mA$$

$$Rb_{max} = \frac{Vcc - Vbe}{Ib_{min}} = \frac{5 - 1}{0.00012} = 132K \Omega$$

$$Rb_{min} = \frac{Vcc - Vbe}{Ib_{max}} = \frac{5 - 1}{0.002} = 2K \Omega$$

We chose $\textbf{Rb = 2K2} \Omega$

## Construction

We use a template to solder the LEDs together. The cube is about 7cm by 7 cm.

Each layer has 16 leds with their cathodes (ground) soldered together.

Each column is composed of 4 anodes (positive), one anode for each layer.

# Software

## How it works

We have 4 layers of 16 LEDs which gives us 16 columns of 4 LEDs.

Each layer is controlled by a transistor which is used to connect all the led's cathode in that layer to the ground.

To control one LED, we just need the layer and the column of that LED.

To light up all the cube is a little tricky because we would need around 64*12mA = 768mA out of the ATMega which is impossible.

So what we do is lighting up every LEDs in one layer at a time and switch to another layer very fast. So we just need 16*12 = 192mA.

By switching very fast between layers, the human eye will have the persistence of vision and will never see the switching but just all the LEDs lit.

To switch between animations, we use a pushbutton soldered on the LED Board. It is connected to the external interrupt pin of the microcontroller.

## Code

You can find the code here in zip format.

Here is a bit of the main.c :

// We use the interrupt INT0 to change the animation
// The interrupt is triggered by a button
interrupt [EXT_INT0] void ext_int0_isr(void)
{
LED1 = ~LED1; // invert LED
nbfunc++;
if(nbfunc>7){
nbfunc = 0;
}
}

// Main
void main (void)
{
int tabCLN[17] = {0};
int tabLYR[5] = {0};
int cln = 0,lyr = 0, i=0;

int switchside = 1;
int nbflakestart = 1;
int t = 0, u = 0;

int delayEnlargingCube = 50;
int delaySwitchSide = 50;
int delayWave = 100;
int delayCross = 100;
int delaySpiral = 15;

Init_initController();  // this must be the first "init" action/call!
#asm("sei")             // enable interrupts
LED1 = 0;           	// initial state, will be changed by timer 1

// Activate LEDS to 0
ledLYR(tabLYR);
ledCLN(tabCLN);

while(TRUE)
{
wdogtrig();	        // call often else processor will reset

LED1 = 0;

switch(nbfunc){
///////////////////////////////////
/////////// ONE BY ONE ////////////
///////////////////////////////////
case 0:
for (lyr=1;lyr<5;lyr++){
clearTabLYR(tabLYR);
tabLYR[lyr] = 1;
ledLYR(tabLYR);

for (cln=1; cln<17;cln++){
clearTabCLN(tabCLN);
tabCLN[cln] = 1;
ledCLN(tabCLN);
delay_ms(20);
}
}
break;
///////////////////////////////////
/////////// ALL LED ///////////////
///////////////////////////////////
case 1:
for (lyr=1;lyr<5;lyr++){
clearTabLYR(tabLYR);
tabLYR[lyr] = 1;
ledLYR(tabLYR);

for (cln=1; cln<17;cln++){
tabCLN[cln] = 1;
}
ledCLN(tabCLN);
delay_ms(1);
}

break;

# Results & Conclusion

The Cube works really well. We didn't had a lot of short circuits the first time we tried to light up all the leds.

The fact that the cube is separated from the main board is great because we can use the board for other projects.

To change the animations, we just have to push the button.

We programmed a few animations which work well as you can see in the video.

LED Cube 4x4x4

It was a fun project to do with a lot of soldering.

In conclusion there is place for improvements and optimization.