My 3x3x3 and 5x5x5 LED cube

Technically, you could light up all the LEDs at one time, but that isnt how the software usually works. Usually you light up one led, or you light up the leds on a plane at one time, but that isnt true of all cubes. For your 3x3x3 cube, you will likely light up between 0 and 9 LEDs at a time. using up to 180mA at a time. each LED has a 33% duty cycle.

You probably want the 150 ohm resistors, but the only problem with using 220 ohm resistors is that they wont be as bright, so it will still work, and the LEDs will last longer at 220 ohms, but it may be insignificant. People using 220 ohm resistors maybe using LEDs with lower forward voltages, red are usually very low.

I think Its possible to do all the other things you list, but you probably wont want to do them.

Ok then I will lower the value from the resistor to around 180 ohm (to be in the middle of safe and bright ;)). So you are saying I can switch on all the grounds from each level (3 grounds in total) and then turn on 1 column so I get a vertical line that is lit. So I also can make a wall of LEDs just by turning on all the grounds and turning on 3 columns?

And I don't get your last sentence :roll_eyes: "I think Its possible to do all the other things you list, but you probably wont want to do them." Are you reffering to an easier way to make a 3x3x3 LED?

You could turn all 3 planes low, and turn one column high, lighting up all 3 LEDs, however, if you are resistored to drive your LEDs at 20mA, and you run 3 LEDs off one controller pin, you will be running 60mA on a device rated for 40, and will likely do damage to the microcontroller (if you run the leds at 10mA, you would be within spec.

You dont need to run the cube that way, the way you normally run a cube is by cycling through each layer, and lighting up just the LEDs in that layer that you want lit, then moving to the next layer. The LEDs appear to all be lit at the same time because of persistence of vision, but they are actually flashing on and off very quickly.

What i was referring to was the way you control the LEDs, there are many ways to do it, but will probably want to run things in loops things in sequence, but technically you dont have to do it that way.

WonderTiger: Each transistor is connected to 1 of the 3 cathode levels.

Cathode will work but normally you'd make each level an anode. This is because most LED drivers chips, etc. are designed to connect to LED cathodes.

WonderTiger: -I calculated with this program: http://led.linear1.org/1led.wiz , that I needed 9*150ohms resistors. Though on the internet I found that most people uses ~220Ohms resistors. I'm not sure why they do that, so if anyone can tell me I would be thankful smiley!

Because trying to run LEDs at exactly 20mA with resistors is a BAD IDEA.

There's about a million threads on the subject in these forums but here's the short version: a) LED resistance isn't constant, it varies with voltage. b) At the "20mA" point, the change in resistance is exponential, ie. a tiny error in voltage can produce a massive error in current. c) Individual LEDs can easily vary by 10% so the error in (b) will happen, damaging the LED.

Solution, either: i) Aim for 15mA (which won't be much dimmer), or ii) Use a constant-current circuit (eg. LED driver chip)

The people who choose 220 Ohm resistors are going for the option (i), ie. run at 15mA.

Thanks to you all! Then I will get resistor aimed @15mA. As well with the programming I will only lit up 1 layer at the time :)!

Control question: If I want to lit up the whole cube, I need to do the following: -Select layer 1 (turn off layer 2/3) -Turn on all LED columns -Turn off all LED columns -Select layer 2 (turn off layer 1/3) -Turn on all LED columns -Turn off all LED columns -Select layer 3 (turn off layer 1/2) -Turn on all LED columns -Turn off all LED columns

Or is this possible as well? (I'm newbie in programming as well ;)): -Select layer 1 (turn off layer 2/3) -Turn on all LED -Turn off layer 1 -Select layer 2 -Turn off layer 2 -Select layer 3 -Turn off layer 3

I will post some pics of building this cube!

WonderTiger: Control question: If I want to lit up the whole cube, I need to do the following: ... Or is this possible as well? (I'm newbie in programming as well ;)): -Select layer 1 (turn off layer 2/3) -Turn on all LED -Turn off layer 1 -Select layer 2 -Turn off layer 2 -Select layer 3 -Turn off layer 3

That will work, yes... (for any pattern which is the same in all three layers)

Ok thanks I will keep it in mind until I got everything soldered up!

Maybe someone want to check this for the last time, to be sure I buy the right stuff:

-Transistor+22kOhms resistor should be fine right? Datasheet transistor: http://www.produktinfo.conrad.com/datenblaetter/150000-174999/163350-da-01-en-Transistor_2N3904.pdf -LED+220 ohms @15mA GREEN. Datasheet LED: http://www.produktinfo.conrad.com/datenblaetter/175000-199999/184705-da-01-en-WU_8_56_GD_LED_5mm_gruen.pdf

Thanks :grin:

You are very close, but there is a critical step that is missing.

Starting with all pins low. Turn plane 1 pin low Turn column pin(s) high Wait some amount of time(1ms or more) Turn column pins low Turn plane pin high

Usually you set things back to a neutral position, unless you know that is what you want in the next step. Usually you turn the light on, wait, turn it off, move to the next step in the sequence.

Usually cubes run static patterns, but they can also be run by calculations (like with the game of life, or random.)

Ye I did forget the delay :|.

Though for me its more like this, right?: Starting with all pins low. Turn plane 1 pin [u]high[/u] Turn column pin(s) high Wait some amount of time(1ms or more) Turn column pins low Turn plane pin [u]low[/u]

I use npn transistors that will switch to ground when current is provided to the base pin from the transistor, this is why I need to set plane 1 to a value HIGH instead of low, right?

Yes, you send high from the microcontroller to the NPN to turn the plane low.

Ok thanks! Then If you can confirm the 22kOhm will be sufficient for the 2N3904 transistor: http://www.produktinfo.conrad.com/datenblaetter/150000-174999/163350-da-01-en-Transistor_2N3904.pdf. Then I will be ready to place my order ;).

Im probably not the best person to ask about what transistor to use. Im actually considering using tiny logic level mosfets instead of BJT type transistors for something that only needs a quarter amp. One of the features of using an n channel mosfet is no resistor required.

No problem, you helped me out alot on other stuff though. Thanks again!!!

I'll guess somebody else can take a look at it :).

Is it possible for somebody to explain me why I need to use a resistor on the base from the transistor? I did alot of reading about why a resistor is needed on the base from the transistor (as NPN switch), but I keep seeing different answer on different forums this makes me understand it less and less. So if someone briefly can explain why a resistor is needed on the base (and how you calculate it) I would be very happy with it :)!

sorry for the newbie questions, still in the learning process :)

The resistor limits the current which might go in and out of whatever is driving the base of the transistor, such as an arduino pin.

WonderTiger: Is it possible for somebody to explain me why I need to use a resistor on the base from the transistor? I did alot of reading about why a resistor is needed on the base from the transistor (as NPN switch), but I keep seeing different answer on different forums this makes me understand it less and less. So if someone briefly can explain why a resistor is needed on the base (and how you calculate it) I would be very happy with it :)!

sorry for the newbie questions, still in the learning process :)

It's because once the voltage applied across the emitter/base junction of a transistor is higher then the forward voltage drop rating for that base/emitter junction it will fully turn on and act like a short circuit drawing current well in excess of it's maximum base current limit (and the maximum output current being drawn from say an arduino output pin when set high that one might wire to the base terminal), so something in the base circuit needs to limit the base current to at or below it's maximum rated current value, and a resistor wired in series with the base terminal just happens to be the simplest way to do that.

Lefty

Thanks for the explanations, now I understand why I needed it.

I got another question about the 13th pin from arduino. According to arduino pin 13th has an built in resistor so I can directly put a LED to pin 13 and ground. When I connect a column on pin 13 does the LEDs shine less bright because there is an extra resistor built in on pin 13(my 220ohm resistor + arduino uno pin 13th resistor?)

WonderTiger: Thanks for the explanations, now I understand why I needed it.

I got another question about the 13th pin from arduino. According to arduino pin 13th has an built in resistor so I can directly put a LED to pin 13 and ground. When I connect a column on pin 13 does the LEDs shine less bright because there is an extra resistor built in on pin 13(my 220ohm resistor + arduino uno pin 13th resistor?)

There is a series resistor/led wired to pin 13 mounted on most arduino boards. However the shield pin 13 is wired directly to the AVR pin so the pin is not protected by the on board resistor, so all the same current rules apply to using pin 13 as with any other AVR I/O pin.

Lefty

All the components are send today! Soon I will start building the cube :grin:.

A little programming question. What will happen when I don't use a delay between switching on and off the LED. I would guess it wouldnt turn on the LED because it's been turned on and off too fast. Will I do damage on any components if I don't use delay.

And it's true the arduino pin can take up to 200mA? So I will be able to put on 9 LEDs on 1 plane ( 9 * ~15mA= 135mA). Thanks for the help again :roll_eyes:.

Got my LED cube build today :D! This code I made as a test:

I used for() loops as delay between the columns as well for making the led columns run at their full brightness.

int layer1 = 11; 
int layer2 = 12;
int layer3 = 13;
int led1   = 10;
int led2   = 9;
int led3   = 8;
int led4   = 7;
int led5   = 6;
int led6   = 5;
int led7   = 4;
int led8   = 3;
int led9   = 2;
int r      = 1;




void setup()
{
  pinMode(layer1, OUTPUT); 
  pinMode(layer2, OUTPUT);    
  pinMode(layer3, OUTPUT);  
  pinMode(led1,   OUTPUT); 
  pinMode(led2,   OUTPUT);  
  pinMode(led3,   OUTPUT);  
  pinMode(led4,   OUTPUT);  
  pinMode(led5,   OUTPUT);  
  pinMode(led6,   OUTPUT);  
  pinMode(led7,   OUTPUT);  
  pinMode(led8,   OUTPUT);  
  pinMode(led9,   OUTPUT);  
  

}

void loop()
{
while(r<=5){
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, LOW);
  digitalWrite (led5, HIGH);
  
 for(int i = 0; i <= 15;i++){
  digitalWrite (layer1, HIGH);
  digitalWrite (led1, HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led1, LOW);
 }

 for(int i = 0; i <= 15;i++){
  digitalWrite (layer1, HIGH);
  digitalWrite (led2, HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led2, LOW);
 }

for(int i = 0; i <= 15;i++){
  digitalWrite (layer1, HIGH);
  digitalWrite (led3, HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led3, LOW);
 }

 for(int i = 0; i <= 15;i++){
  digitalWrite (layer1, HIGH);
  digitalWrite (led6, HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led6, LOW);
 }

 for(int i = 0; i <= 15;i++){
  digitalWrite (layer1, HIGH);
  digitalWrite (led9, HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led9, LOW);
 }

 for(int i = 0; i <= 15;i++){
  digitalWrite (layer1, HIGH);
  digitalWrite (led8, HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led8, LOW);
 }

 for(int i = 0; i <= 15;i++){
  digitalWrite (layer1,  HIGH);
  digitalWrite (led7,    HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led7, LOW);
 }
 for(int i = 0; i <= 15;i++){
  digitalWrite (layer1, HIGH);
  digitalWrite (led4, HIGH);
  delay(1);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(1);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(1);
  digitalWrite (layer3, LOW);
  digitalWrite (led4, LOW);
 }
 digitalWrite (led5, LOW);
 digitalWrite (layer1, LOW);
 digitalWrite (layer2, LOW);
 digitalWrite (layer3, LOW); // RESET all layers to OFF
 r = r++;                     
}
r = 1;                        
while (r<=10){
  digitalWrite (layer1, HIGH);
  digitalWrite (led1, HIGH);
  digitalWrite (led3, HIGH);
  digitalWrite (led7, HIGH);
  digitalWrite (led9, HIGH);
  delay(75);
  digitalWrite (layer1, LOW);
  digitalWrite (layer2, HIGH);
  delay(75);
  digitalWrite (layer2, LOW);
  digitalWrite (layer3, HIGH);
  delay(75);
  digitalWrite (led1, LOW);
  digitalWrite (led3, LOW);
  digitalWrite (led7, LOW);
  digitalWrite (led9, LOW);
  delay(75);
  digitalWrite (led2, HIGH);
  digitalWrite (led4, HIGH);
  digitalWrite (led6, HIGH);
  digitalWrite (led8, HIGH);
  delay(75);
  digitalWrite (layer3, LOW);
  digitalWrite (layer2, HIGH);
  delay(75);
  digitalWrite (layer2, LOW);
  digitalWrite (layer1, HIGH);
  delay(75);
  digitalWrite (led2, LOW);
  digitalWrite (led4, LOW);
  digitalWrite (led6, LOW);
  digitalWrite (led8, LOW);
  r = r++;
}
r=1;
}

Here a video :): http://www.youtube.com/watch?v=4nfarTktGv8 If anyone has some tips what I could do better on my code, feel free to let me know :).