Tuesday, September 7, 2010

6

ARDUINO 4x4x4 LED CUBE


This post is dedicated to my dear friend Luis Reig. Some time ago we found an interesting instructable explaining how to build a 4x4x4 LED cube so we decided to start building it.



We bought all the components and after soldering together all the LEDs we kind of abandoned the project due to lack of time.

The LED cube described in the instructable was controlled using an Atmel Atmega16 micro-controller and some custom circuitry. But with arduino it is extremely easy to control the cube.

You see, there is 64 LEDs in the cube. If you want to control each LED individually you would need 64 digital control lines. Running a wire to each individual LED would be very impractical and look really bad, fortunately there is a trick that you can do: split the cube in 4 layers of 16 LEDs.

The cube is distributed in 4 horizontal layers and 16 vertical columns. All the LEDs in a given layer share the negative pole and the LEDs in a given column share the positive pole.  So all we need now is 4+16 = 20 control lines. Arduino provides 14 digital control lines (Digital 0 to 13) and 6 analog lines (Analog 0 to 5) that can be used as Digital lines (referenced as Digital 14 to 19) making a total of 20 digital control lines.

With this you can light up all the LEDs individually or light up all the LEDs in the same layer or all the LEDs in the same column. Of course, there is combinations that give some trouble but you can avoid them by using Persistence of Vision.

Here you can see a video testing the cube:



And the source code for arduino (persistence of vision is not yet implemented):

/*

   LED Cube test
   Author: Martin Peris-Martorell - www.martinperis.com


   This program is designed to perform a basic test
   on a 4x4x4 LED cube.

   It lights up each led individually, lights up
   the hole cube and starts again.

   This program is distributed under the terms of the 
   GNU General Public License.
   
   Enjoy it.

*/


void setup(){

  pinMode(0,OUTPUT);
  pinMode(1,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
  pinMode(14,OUTPUT);
  pinMode(15,OUTPUT);
  pinMode(16,OUTPUT);
  pinMode(17,OUTPUT);
  pinMode(18,OUTPUT);
  pinMode(19,OUTPUT);

  digitalWrite(16,LOW);
  digitalWrite(17,LOW);
  digitalWrite(18,LOW);
  digitalWrite(19,LOW);
}

void loop(){
  int i,j;


  /* Light up LED by LED */
  for (i = 16; i < 20; i++){
    digitalWrite(i,HIGH);
    for (j = 0; j < 16; j++){
      digitalWrite(j,HIGH);
      delay(200);
      digitalWrite(j,LOW);
    }
    digitalWrite(i,LOW);
  }

   /* BLINK COMPLETE LED */
  for (i = 0; i < 20; i++){
    digitalWrite(i,HIGH);
  }
  delay(1000);
  for (i = 0; i < 20; i++){
    digitalWrite(i,LOW);
  }

}

6 comments:

botellon said...

Al final lo has hecho, mola.
Estaba pensando que molaría encender un segmento en el centro y rotarlo en x,y,z sobre el centro del cuadrado.

Martin Peris said...

Si estaria chulo, en cuanto tenga implementado el POV (Persistence of Vision) se podran hacer todos los efectos que se quiera :D

Anonymous said...

do i need a transistor?

Martin Peris said...

Yes, actually you need 4 NPN transistor BC338 (or other transistor capable of switching 250-ish mA)

Anonymous said...


I am very happy to read this.

Unknown said...

de que valor son las resistencias que usaste?? me ayudaría muchísimo.
De antemano gracias

Post a Comment