Resistor value for my led cube?

Hi,

I've built a 5x5 ledcube with basic 3mm red led's. The microcontoller i'm using is an Arduino Mega.

My led cube has 25 columns(anodes) and 5 rows(cathodes). Each column has a 220 Ohm resistor. I use pin 22 to 46 for the columns and pin A0 to A4 for the rows. Each column controls 5 led's one row is pulled down to light up the right led of the five.

The specs for the led's:
If: 20 mA
Uf: 2V

If I apply Ohm's law to calculate the max current through each column I get ~23 milliamps, which is above the max forward current(If), but it's probably fine because a single led is never on for a long amount of time. How much current will sink into the arduino?

Thanks!

You nearly understood a multiplexed display :slight_smile:

When you only turn on one row at a time, only these (five) LED can draw current at a time. If you prevent all rows from ever being on together, what may happen during a reset or power off of the Arduino, you're fine so far.

Now for the current calculation, assuming that you drive the rows and columns by 5+5 output pins. Then the controller limits the total output current to 200mA (typically, see data sheet), and the individual output pin current to 40mA.
The column outputs drive only a single LED at a time, no problem so far. The row outputs instead drive all LED in a row at the same time, here up to 5*led_current, so that a single LED can be driven at 40mA/5 = 8mA. When a LED is on for 1/5 of time only, this will result in an average (effective) LED current of 8/5 = 1.6mA - not really much :frowning:
If you need brighter LEDs, you have to add transistors to at least the row outputs, that withstand higher currents.

When a LED is specified at 20mA continuous current, it usually will tolerate the same effective current when pulsed. If so, the pulse current can be increased by the pulse duty cycle (20mA/(1/5)=20mA*5=100mA). When driven from 5V logic outputs the column resistor would be >= (5V-2V)/100mA=30 Ohm.
Since we already know that an output pin supports only 40mA, this would damage our poor Arduino. So let's calculate the resistor for the this limit: 40mA/5colums=8mA, (5V-2V)/8mA=375 Ohm. Now you see that your choice of 220 Ohm is much too low :frowning:

As a quick solution you can replace the resistors by 2 in series (440 Ohm), or by 390 Ohm if at hand.

DrDiettrich:
You nearly understood a multiplexed display :slight_smile:

When you only turn on one row at a time, only these (five) LED can draw current at a time. If you prevent all rows from ever being on together, what may happen during a reset or power off of the Arduino, you're fine so far.

Now for the current calculation, assuming that you drive the rows and columns by 5+5 output pins. Then the controller limits the total output current to 200mA (typically, see data sheet), and the individual output pin current to 40mA.
The column outputs drive only a single LED at a time, no problem so far. The row outputs instead drive all LED in a row at the same time, here up to 5*led_current, so that a single LED can be driven at 40mA/5 = 8mA. When a LED is on for 1/5 of time only, this will result in an average (effective) LED current of 8/5 = 1.6mA - not really much :frowning:
If you need brighter LEDs, you have to add transistors to at least the row outputs, that withstand higher currents.

When a LED is specified at 20mA continuous current, it usually will tolerate the same effective current when pulsed. If so, the pulse current can be increased by the pulse duty cycle (20mA/(1/5)=20mA*5=100mA). When driven from 5V logic outputs the column resistor would be >= (5V-2V)/100mA=30 Ohm.
Since we already know that an output pin supports only 40mA, this would damage our poor Arduino. So let's calculate the resistor for the this limit: 40mA/5colums=8mA, (5V-2V)/8mA=375 Ohm. Now you see that your choice of 220 Ohm is much too low :frowning:

As a quick solution you can replace the resistors by 2 in series (440 Ohm), or by 390 Ohm if at hand.

DrDiettrich:
You nearly understood a multiplexed display :slight_smile:

When you only turn on one row at a time, only these (five) LED can draw current at a time. If you prevent all rows from ever being on together, what may happen during a reset or power off of the Arduino, you're fine so far.

Now for the current calculation, assuming that you drive the rows and columns by 5+5 output pins. Then the controller limits the total output current to 200mA (typically, see data sheet), and the individual output pin current to 40mA.
The column outputs drive only a single LED at a time, no problem so far. The row outputs instead drive all LED in a row at the same time, here up to 5*led_current, so that a single LED can be driven at 40mA/5 = 8mA. When a LED is on for 1/5 of time only, this will result in an average (effective) LED current of 8/5 = 1.6mA - not really much :frowning:
If you need brighter LEDs, you have to add transistors to at least the row outputs, that withstand higher currents.

When a LED is specified at 20mA continuous current, it usually will tolerate the same effective current when pulsed. If so, the pulse current can be increased by the pulse duty cycle (20mA/(1/5)=20mA*5=100mA). When driven from 5V logic outputs the column resistor would be >= (5V-2V)/100mA=30 Ohm.
Since we already know that an output pin supports only 40mA, this would damage our poor Arduino. So let's calculate the resistor for the this limit: 40mA/5colums=8mA, (5V-2V)/8mA=375 Ohm. Now you see that your choice of 220 Ohm is much too low :frowning:

As a quick solution you can replace the resistors by 2 in series (440 Ohm), or by 390 Ohm if at hand.

Hi, I changed my question a bit because it seemed very vague after reading it back. Basically, each column is "pillar" of 5 led's connected by the anodes. Each row is 25 leds connected by their cathodes. So for example, pulling column 1 to high and all the rows to low will result in all the 5 led's of column 1 to light. If only row 1 is low, then only one led of the column will light up.

Some questions I have about your answer:

  • The tl;dr is that 220 Ohm's per column(of 5 leds) is not enough, I need somewhere around 400 Ohms?

  • Will 220 Ohms damage the led's or the arduino(or both?).

  • what do you mean by 5+5 output pins?

  • What do you exactly mean with on for 1/5 of the time? Lighting up the leds in sequence, so if one column is lit up for 50 second then each single led is lit up for 10 seconds?

  • When a LED is specified at 20mA continuous current.... You lost me after this :stuck_out_tongue:
    -- What is the difference between continuous current and effective current?
    -- What is is pulse current?
    -- 30 Ohm is the resistance of all the leds on a column without adding any resistors?

When using transistors, the output pins of the arduino activate the flow of current through the transistor. This way, higher current fllow can be used. But what would be the ground for the transistors in this case? Back to the power source I guess? But how can I pull an Arduino pin high if it's not connected to the ground of the arduino?

Ow and the led cube is running for an hour now without any trace of damage :P. Honestly I would rather have the arduino brake than the led's because soldering the led's is a big pain.

Please clarify: how can each row be connected to 25 LEDs? This would mean a total of 125 LED in 5 rows?

Driving 5 columns independently requires 5 column output pins, and 5 more row pins for 5 independent rows, a total of 5+5 pins.

You also said that each column has a resistor. Then it does not make sense to pull one column high and all rows low, because then the resistor limits the current of all 5 LEDs at the same time - making the current through 1 LED depend on the number of active rows! Instead you should pull one row low, so that up to 5 columns can be high, and the current in every column is limited by a different resistor.

The effective current of a square wave signal depends on the duty cycle. When a LED is on all the time (100%), the effective current is equal to that continuous (peak) current. When the LED is on only 20% of the time, the effective current drops down to 20% of the peak current (during on phase). This is how PWM works.

Now for the calculations. A LED or other diode is a non-linear resistor, not following Ohm's law. Instead the forward voltage (Uf) is almost constant over the allowed current range, in your case 2V. When driven by 5V, there remain 5V-2V=3V for the resistor, So you can calculate I=U/R or R=U/I.

The currents through five 220 Ohm column resistors and five LED (all column pins high) will sum up in the active (low) row pin (Kirchhoff's law). The LEDs will survive easily, but not the row pin.

DrDiettrich:
The LEDs will survive easily, but not the row pin.

That is why row drivers are usually used, not bare digital outputs. It's a poor design, that doesn't.

DrDiettrich:
Please clarify: how can each row be connected to 25 LEDs? This would mean a total of 125 LED in 5 rows?

Yes, this is basically what I have:

Each row(floor?) has 25 leds connected by their cathodes. Each row of 25 leds have one common cathode so I have 5 rows that are going to A0 - A4. Each one of the 25 columns has 5 leds connected by their anodes the columns are connected to pin 22 - 46 and there is a resistor for every row. So in total I have 25 220 Ohm resistors.

You also said that each column has a resistor. Then it does not make sense to pull one column high and all rows low, because then the resistor limits the current of all 5 LEDs at the same time - making the current through 1 LED depend on the number of active rows! Instead you should pull one row low, so that up to 5 columns can be high, and the current in every column is limited by a different resistor.

Yes, if I I pull one row low, only one led will light up for every column that is pulled high, so one resistor for one led. But If I want to light up two leds on a column, I have to pull two rows low and if I want to light up all the leds on a column then I have to pull all the rows to low. So if I want to light up more than one led per column at the same time, then the current through one led is dependent on the amount of rows pulled low you're right. However, I'm not sure why, but the brightness of all the leds is the same no matter how many rows are pulled low. even If all the 125 leds are on at the same time, I can't see any difference on the brightness per led. I also tried switching the leds to low in sequence very fast, so that it looks like all the leds are on at the same time, but this did effect the brightness of the leds. The leds seemed much fainter using this method.

The effective current of a square wave signal depends on the duty cycle. When a LED is on all the time (100%), the effective current is equal to that continuous (peak) current. When the LED is on only 20% of the time, the effective current drops down to 20% of the peak current (during on phase). This is how PWM works.

I don't use PWM, I just set a digital pin to high or low. So does this still apply?

Now for the calculations. A LED or other diode is a non-linear resistor, not following Ohm's law. Instead the forward voltage (Uf) is almost constant over the allowed current range, in your case 2V. When driven by 5V, there remain 5V-2V=3V for the resistor, So you can calculate I=U/R or R=U/I.

My knowledge of electricity is to limited to understand this. What am I even calculating? The remaining current that sinks in to the row pin?

Go with some active row drivers, either with some transistors taking over the load or with a cheap transistor array.

rpt007:
Go with some active row drivers, either with some transistors taking over the load or with a cheap transistor array.

If I use a transistor for every row, the collector is connected to the common cathode of one row, the base is connected to an arduino output to activate the transistor, the emitter is left floating?

Just have a look at this, which comes with transistor arrays as you will need more than one transistor. Those ULN.. transistor arrays are pretty cheap, deliver enough power and ease your life in soldering the things together.

You have been talking about 5 columns and 5 rows, what's enough to light the LEDs in a single plane, and that's what I was talking about. Now you show 25 columns and 5 rows, forming a cube. So let's restart with that configuration in mind.

How do you connect those 30 lines to your Arduino? A Mega has enough output pins, and eventually can drive the columns directly, but the rows definitely need drivers for the high row current. The drivers can be transistors or IC (SN7445, TPIC6B595), capable to sink the current from 25 LEDs. Which solution do you have in mind?

Okay, you want to use transistors. Transistor arrays may be usable, but not Darlington transistors, I think. Then you connect all emitters to Gnd, and the collectors to the cathodes of a row. For connecting the transistor bases to the digital output pins you need current limiting resistors, like for the LED columns, the values depend on the current gain of the selected transistor.

A possibly simpler solution are logic level FETs, which can be driven directly from output pins, and have almost zero voltage drop in on state. Bipolar (NPN) transistors have a voltage drop of about 0.4V, Darlington transistors more than 1V. A high voltage drop makes it hard to control the LED current, because the voltage on the current limiting resistor becomes very low, and the Arduino pins add another voltage drop, so that in the worst case no voltage is left on the anode resistors. Which solution (transistor type) do you have in mind?