# Help check my (basic) understanding

I am new to this world of the arduino (and electronics in general to be more precise) and have spent some time trying to wrap my head around many of the concepts. After much reading I’ve decided to jump into building a 3x3x3 cube (wanted to do a 4x4x4 but think a 3x3 is more prudent for a first project).

I’ve gone ahead a purchased a number of blue LED’s from eBay which have the following specs - 3.0-3.4v, 3.22v typical, 24mA max, 13000 mcd. In trying to calculate the resistors I need I’ve both used an online “calculator” and more importantly tried to apply Ohm’s law as I understand it… And, this is where I need my understanding to be checked.

I understand that the Arduino Uno works at 5V. So, if I am applying Ohm’s law correctly, I need to calculate the “voltage drop” (which I am equating to the remaining voltage after the LED), and divide by the current I want the circuit to draw (in this case based on what the LED can handle):

R=V/I
R=(5 - 3.2)/.02A == 90ohm resistor required (this uses an avg voltage of the LED and assumes a chosen 20mA current)

So, I think I should be rounding up to a 100ohm resistor to prevent more than 20mA going through the LED. This is consistent with what the calculators are returning. I assume rounding up to a higher resistor will simply limit the current available for use by LED resulting in an imperceptibly dimmer LED.

What I am not 100% on is how the the arduino’s output current plays into this (or if it does at all). I understand that the max input or output the pins can handle is 40mA. I assume that it is the resistor that limits the current from the pin, hence an additional reason for choosing 20mA in the above equation. So, hypothetically if I used a smaller resistor more current would flow through the LED potentially damaging it and the in/output pin.

Eg. - using an imaginary 10ohm resistor
I=V/R
I=1.8/10 = .18 amps or 180mA == damage to the LED and i/o pin

Does all of this sound right?

You got it pretty much right.

Arduino pins can supply 40 mA with a total of 200 mA for the entire atmega328 chip. However, with a 100 Ohm resistor and a single led connected to a pin, the 40 mA maximum is not an issue.

However... 3x3x3 = 27 leds, drawing each 20 mA makes 20x27 = 540 mA which is more than your arduino can supply. I suggest using a led driver, transistor, mosfet, whatever makes you happy.

I build an 8x8x8 ledcube which was fed of 595 shift registers. No, not what they are intended for, yes, pushing the limits on how much current they can supply, and mostly: yes, a very convenient hack.

So first find it how you want to supply power for your 27 leds. Each pin of a 595 register typically supplies 30-35 mA. This will do for you. To drain a plane of 9 leds, use a transistor. If you want more advice it might help to post your proposed schematic for your ledcube.

Cheers !

Jack

However... 3x3x3 = 27 leds, drawing each 20 mA makes 20x27 = 540 mA which is more than your arduino can supply. I suggest using a led driver, transistor, mosfet, whatever makes you happy.

Keep in mind that most all led cube designs never try and turn on all the leds on at any single instant of time, but rather a 'level' at a time so for a 3x3x3 design there would never be more then 9 leds drawing current at any given instant, so no problem for the arduino 5v pin suppling that total current. It's the multiplexing timing that can make it appear that all 27 leds can be on at the same time, but it's simply an optical allusion as the human eye can't resolve faster time spans.

Lefty

vtterp: Does all of this sound right?

Yes...but bear in mind that some of your LEDs might only need 3.0V.

If you use the 'correct' resistor for 3.2V then the 3.0V LEDs might receive much more than 20mA. This is because a LED doesn't have a constant resistance. The resistance of a LED varies with the voltage across it and drops away exponentially as you approach the 'optimum' (in this case when you get 20mA). At 20mA a tiny error in voltage can produce a massive error in current, enough to hurt the LED.

To light up a LED safely you should either: a) Use a circuit which controls current, not voltage (eg. A LED driver chip). b) Aim for less than maximum current, eg. 15mA (the LED resistance curve is much flatter here so errors don't matter as much).

If you use the 'correct' resistor for 3.2V then the 3.0V LEDs might receive much more than 20mA.

I think you are over stating the case. If a led with a nominal 3.2vdc Vc rating was actually 3.0 Vf then the 90 ohm resistor would limit the current to 22 ma, hardly a thing to be concerned about, right? There can be more then that much variation in the arduino boards Vcc voltage depending on the USB voltage allowance of 4.75 to 5.25 vdc standard.

Lefty

Thanks for the quick replies. At least I now feel like I am making some sense of all of this in my head... and yet it is clear I have a long way to go :)

I was under the impression that because of multiplexing I wouldn't be pushing the arduino too much. LED driver chips and the like are beyond my skill set at the moment, but I will certainly add them to the list of items to research.

Jack - I'll be working on the schematic over the next few days and will post once it's complete. I am thinking of using gzip's build as a go-by http://www.instructables.com/id/LED-Cube-and-Arduino-Lib/?ALLSTEPS.

vtterp: Thanks for the quick replies. At least I now feel like I am making some sense of all of this in my head... and yet it is clear I have a long way to go :)

Your understanding of the principals at hand have been just fine, your learning journey is off to a fine start.

I was under the impression that because of multiplexing I wouldn't be pushing the arduino too much. LED driver chips and the like are beyond my skill set at the moment, but I will certainly add them to the list of items to research.

That is correct, a 3x3x3 led cube will be no problem being powered by your arduino board. You will need 3 transistors to drive the three 'levels' as a 'level driver' via 3 output pins, as it has to be able to supply up to 9 X 20 ma, more then a output pin can handle by itself. So you will need to use 12 digital pins, but keep in mind that the analog input pins can function as digital pins just by using pin numbers 14 to 19, so a Uno board is good to go.

Lefty

Jack - I'll be working on the schematic over the next few days and will post once it's complete. I am thinking of using gzip's build as a go-by http://www.instructables.com/id/LED-Cube-and-Arduino-Lib/?ALLSTEPS.

retrolefty:

If you use the ‘correct’ resistor for 3.2V then the 3.0V LEDs might receive much more than 20mA.

I think you are over stating the case. If a led with a nominal 3.2vdc Vc rating was actually 3.0 Vf then the
90 ohm resistor would limit the current to 22 ma, hardly a thing to be concerned about, right?

“The resistance of a LED varies with the voltage across it and drops away exponentially as you approach 20mA…”

Here’s an actual graph from the datasheet of a real-life red LED rated at 2.0V-2.5V. Let’s see what an error of 0.2V does…

At 2.2V you get 20mA - perfect!.

At 2.4V you get about 45mA - more than double the current at 2.2V and enough to kill the LED (its maximum rating is 30mA).

So no, I don’t think I’m overstating anything.

You are confused - the resistor sets a relationship between current and voltage, so does the LED, the actual voltage/current is determined by where the response curve of the LED crosses the load-line of the resistor. The current won't double or anything remotely like it.

LED that takes 20mA at 3.2V, 90 ohm resistor drops 1.8V at 20mA - all consistent. LED that takes 45mA at 3.2V, 90 ohm resistor drops 4.05V, therefore LED gets 0.95V - doesn't happen.

What happens is a bit more current flows, the voltage across the resistor increases, then the LED ends up with about 3.0V across is and about 20mA flowing through it. Hence the name "current limiting".

If the supply voltage was 3.3V though, this limiting effect would be much poorer - by throwing away 1.8V you gain current stability.

A blue LED at 20mA is also blindingly bright. So, I would shoot for 10mA and the whole babysitting millivolt differences becomes moot. :-) IMHO.

fungus:

retrolefty:

If you use the 'correct' resistor for 3.2V then the 3.0V LEDs might receive much more than 20mA.

I think you are over stating the case. If a led with a nominal 3.2vdc Vc rating was actually 3.0 Vf then the 90 ohm resistor would limit the current to 22 ma, hardly a thing to be concerned about, right?

"The resistance of a LED varies with the voltage across it and drops away exponentially as you approach 20mA..."

Here's an actual graph from the datasheet of a real-life red LED rated at 2.0V-2.5V. Let's see what an error of 0.2V does...

At 2.2V you get 20mA - perfect!.

At 2.4V you get about 45mA - more than double the current at 2.2V and enough to kill the LED (its maximum rating is 30mA).

So no, I don't think I'm overstating anything.

Your graph is not taking into consideration the effect of the series current limiting resistor, which is what the conversation is all about, proper sizing of such a resistor. Your graph is showing the effect of a non current limiting voltage source driving the led. We simply are not driving the led with a constant voltage source, but rather a current limited source. Your graph show why it is important to use current limiting resistor with low power leds, which some people still feel are not required, if they can some how control the source voltage, which as your graph shows is a dangerous route to take.

Lefty

retrolefty: Your graph is not taking into consideration the effect of the series current limiting resistor, which is what the conversation is all about, proper sizing of such a resistor. Your graph is showing the effect of a non current limiting voltage source driving the led. We simply are not driving the led with a constant voltage source, but rather a current limited source. Your graph show why it is important to use current limiting resistor with low power leds, which some people still feel are not required, if they can some how control the source voltage, which as your graph shows is a dangerous route to take.

Hang on...I'm being thick, aren't I?

Just because much more current could go through the LED with a 0.2V change, it doesn't mean much more current could go through the resistor. The voltage across the resistor only changes by 0.2V so the difference in current will be in proportion.

I stand corrected.

retrolefty:

vtterp:
I was under the impression that because of multiplexing I wouldn’t be pushing the arduino too much. LED driver chips and the like are beyond my skill set at the moment, but I will certainly add them to the list of items to research.

That is correct, a 3x3x3 led cube will be no problem being powered by your arduino board. You will need 3 transistors to drive the three ‘levels’ as a ‘level driver’ via 3 output pins, as it has to be able to supply up to 9 X 20 ma, more then a output pin can handle by itself. So you will need to use 12 digital pins, but keep in mind that the analog input pins can function as digital pins just by using pin numbers 14 to 19, so a Uno board is good to go.

Lefty

So, I’ve gone back to a 4x4x4 and am having a conversation with myself regarding the need for transistors. As the Uno can utilize 20 pins (16 columns, 4 rows) as digital pins and because of multiplexing, shouldn’t I be able to (safely) get away without transistors? Regardless, I am amidst some heady (for me) reading on transistors and hope to understand the use of them for this project if necessary. I have some 2N2222’s here and was initially planning on using these on the rows but am having some serious trouble understanding the calculations behind choosing correct resistors to use with the transistors. Any “beginner language” help would be greatly appreciated.

I’ve also attempted a first draft of a schematic for this project (attached). It assumes the use of transistors but does not include the connections to the Uno. I plan to have the columns connect to “digital” pins 0-13 and “analog” 0-1, while the rows will connect to “analog” 2-5. Thoughts? Am I tracking in the right direction?

Nickity - I am planning on “diffusing” the LEDs by sanding them. While this won’t diminish the brightness, I hope it will prevent the need for sunglasses.

So, I've gone back to a 4x4x4 and am having a conversation with myself regarding the need for transistors. As the Uno can utilize 20 pins (16 columns, 4 rows) as digital pins and because of multiplexing, shouldn't I be able to (safely) get away without transistors?

No. Think about a given pattern you may want to display that turns on all 16 leds of a single level (Row) going to a single output pin driving that row. That could be 16 X 20 milliamos of current which is more then the poor row enable pin can supply, hence the need to use 4 switching transistors to drive the 4 levels (Row). That make sense?

Regardless, I am amidst some heady (for me) reading on transistors and hope to understand the use of them for this project if necessary. I have some 2N2222's here and was initially planning on using these on the rows but am having some serious trouble understanding the calculations behind choosing correct resistors to use with the transistors. Any "beginner language" help would be greatly appreciated.

A 2N2222A transistor is really not able to switch 16 x 20ma of current, you need a 'bigger' transistor.

I've also attempted a first draft of a schematic for this project (attached). It assumes the use of transistors but does not include the connections to the Uno. I plan to have the columns connect to "digital" pins 0-13 and "analog" 0-1, while the rows will connect to "analog" 2-5. Thoughts? Am I tracking in the right direction?

Keep in mind that pins 0 and 1 are used to upload sketches into your chip, so you may need to be able to easily remove things you wire to pins 0 and 1 when you need to upload a sketch and then reattach them.

Nickity - I am planning on "diffusing" the LEDs by sanding them. While this won't diminish the brightness, I hope it will prevent the need for sunglasses.

Others have tried many methods of manually diffusing clear leds with rather poor effect, including sanding, painting, etching, etc. But maybe you will have better luck. One thing is clear that led cubes should definitely utilize diffused leds, otherwise the visual effects lose a lot if the leds have narrower output beam, making the angle of viewing of the cube poor, the effects just won't be as good as using diffused leds. Lefty

I built an indicator out of various 3mm colored LEDs. The red, green, yellow, and blue LEDs were all diffused, but the white was clear. I sanded it with a fine sandpaper and it turned out great. Easy does it though, a little goes a long way. I canned my first attempt because I had sanded several flat spots into it. ;-) (Technically, I didn't can it, I just use it for breadboard projects where I don't care about the visual quality. Why waste a good LED?)

At the risk of being a FET pusher, try a small MOSFET instead. This is the perfect sort of application for them. You should use a small (100-200R will do fine) resistor for good measure, but the FET gate (analogous to the base of a BJT) has a high impedance, so there's no need to current limit or calculate gains. You'll need a logic level FET.

I use VN10LPs for moderate current (270mA) -- here's a link to Digikey: http://www.digikey.com/product-detail/en/VN10LP/VN10LP-ND/92610

If you're driving them all at a full 20mA, you'll need something with more gusto. Here's a ZVN4206A good for 600mA: http://www.digikey.com/product-detail/en/ZVN4206A/ZVN4206A-ND/92604

Those are both N-channel, so you'll be switching between the LED and ground. (Same as NPN.)

retrolefty: No. Think about a given pattern you may want to display that turns on all 16 leds of a single level (Row) going to a single output pin driving that row. That could be 16 X 20 milliamos of current which is more then the poor row enable pin can supply, hence the need to use 4 switching transistors to drive the 4 levels (Row). That make sense?

Regardless, I am amidst some heady (for me) reading on transistors and hope to understand the use of them for this project if necessary. I have some 2N2222's here and was initially planning on using these on the rows but am having some serious trouble understanding the calculations behind choosing correct resistors to use with the transistors. Any "beginner language" help would be greatly appreciated.

A 2N2222A transistor is really not able to switch 16 x 20ma of current, you need a 'bigger' transistor.

Yes, that does make sense. I was assuming (incorrectly) that multiplexing was for every LED. That is, only one LED would ever be lit at a time, not just for those in a single column (driven by a single pin).

I am starting to track with the transistors and think I am getting some of the math down...

So the max current that would potentially need to be sunk(?) from one level is 20mA*16 == 320mA I've read that you should build in some sort of safety factor, of say 2, when selecting the transistor. In this case I would need a transistor with a collector current (Ic) of 640mA minimum.

What should I set by base current (Ib) to? I understand it can be low. Is there a rule of thumb at play here? I'll assume 20mA for the Ib?

Hfe, or the gain (amplification) to the base current, is allegedly calculated Hfe==(5*Ic)/Ib where 5 is a factor used to ensure the switch closes "hard." If this is correct, Hfe=(5*.64)/.02 == 160mA min. I think things are falling apart here as I am not finding transistors that seem to fit this math. If things were correct, I'd now go to the store and try to find a transistor that has a minimum Hfe of 160mA, with a minimum Ic of 640mA, operating at 5V (or should this be 5V - LED voltage drop?).

When trying to "shop" online for a transistor that fits the above specs I was not finding much. I believe I am doing something horribly wrong here.

SirNickity: I built an indicator out of various 3mm colored LEDs. The red, green, yellow, and blue LEDs were all diffused, but the white was clear. I sanded it with a fine sandpaper and it turned out great. Easy does it though, a little goes a long way. I canned my first attempt because I had sanded several flat spots into it. ;-) (Technically, I didn't can it, I just use it for breadboard projects where I don't care about the visual quality. Why waste a good LED?)

At the risk of being a FET pusher, try a small MOSFET instead. This is the perfect sort of application for them. You should use a small (100-200R will do fine) resistor for good measure, but the FET gate (analogous to the base of a BJT) has a high impedance, so there's no need to current limit or calculate gains. You'll need a logic level FET.

I use VN10LPs for moderate current (270mA) -- here's a link to Digikey: http://www.digikey.com/product-detail/en/VN10LP/VN10LP-ND/92610

If you're driving them all at a full 20mA, you'll need something with more gusto. Here's a ZVN4206A good for 600mA: http://www.digikey.com/product-detail/en/ZVN4206A/ZVN4206A-ND/92604

Those are both N-channel, so you'll be switching between the LED and ground. (Same as NPN.)

Nickity, I'm digging this route since, frankly, it seems clearer to me... but that's probably b/c I haven't sunk down into the weeds yet. Is there a benefit/drawback to running these at 20mA vs something lower? It looks like the circuit will all be laid out in the same fashion so there isn't much difference between the two. Would there be any difference in the programming?

Thanks for helping me through this beginning frustration!

It's pretty much that simple. In my opinion, BJTs are more applicable for linear amplification circuits.. take something and make it bigger (in this case, current.) FETs are ideal as switches. They'll both do either, but their characteristics lend themselves to applications. Some will disagree.

On a FET, you need to provide enough voltage to get it switched fully on. The spec sheet will list Rds(on) at a particular voltage. You want to provide the voltage listed in this spec, not the Vgs(thresh) spec. That's where it's just beginning to turn on.

On LEDs.. the current defines brightness. More current, brighter. Less current, dimmer -- and cooler. :-) Nothing special there really.

I too prefer logic level mosfets for simple switching applications. There was a time when the price and device choices were not as good as they are today, but now logic level mosfets of all current/voltage ratings are easy to find.

And as far as defining what current to run leds at in led cube applications, that is one of the real advantages of using external serial in/parallel out shift register to drive the columns. They (some of them anyway) have programmable constant current output drivers. So instead of building your design using fixed current limiting resistor and not really knowing how the final brightness will work out you can change a single resistor on a 16 bit shift register that will change the current value for the leds. So you don't have to commit so early in the design to what brightness level you will end up with.

Lefty

Nickity & Lefty,

Thank you for the patience and for helping me understand these basic concepts. This is a great, supportive community. Parts are en route from digi-key.

More questions to come no doubt...