I am building a 4x4x4 led cube and going to control it by an Arduino Uno. Each column in the cube shares its anode and each layer shares their anodes. In my code I'm switching each layer rapidly, giving the persistence the led is fully enlighted. For more details see this instructable: http://www.instructables.com/id/The-4x4x4-LED-cube-Arduino/?ALLSTEPS
The problem I have is that I am a little worried about the current. If one layer if fully lit, 16 leds will be drawing current. So in order not to exceed the total current the Arduino is rated for, the current for each led should be below 200/16 = 12.5 mA. So I used some resistors to make sure the current on each pin is below that and my current per pin (source) is about 10 mA. So no problem there.
However, in the instructable each layer is routed directly to a pin on the Arduino. If at some point a layer is fully lit it would need to sink 160 mA, well above the limit of 40mA per pin. So to my understanding I will ruin the Arduino if I built my circuit this way. My solution to this would be to use transistors for each layers. Connecting the base of the transistor to one of the pins of the Arduino and the other pins of the transistor to the layer of the led cube and the ground of the Arduino respectively.
Now, me being quite new to electronics I question myself. Why do so much instructables not use transistors? Don't they risk sinking to much current to the pins of the Arduino? If I'm going to need transistors, would this one suit my purpose: BC550 datasheet(2/8 Pages) PHILIPS | NPN general purpose transistors
It can handle peak currents of 200mA. As I am switching between each layer very rapidly would this be okay?
I think you've perfectly analysed it yourself (maybe an expert on the matter can say how the arduino handles 160mA at a duty cycle of 25%, but i think it's still likely to cause damage to your arduino). Learning arduino & multiplexing myself atm, and i've also seen a lot of instructibles which raise some doubts, and will probably damage components (or have better ways to solve the issue).
And the solution you propose also is correct (but maybe pick some transistors that can handle a bit more current? the ones you chose there will really be at their limits, and you'll have the fun of having components that get hot).
'328P can handle 200mA of current, but it has to be spread across the ports:
Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:
ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.
2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.
If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition.
Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:
ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100mA.
2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA.
3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100mA.
If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.
You are much better off using high current capable shift register such as TPIC6B595 to sink current from common cathode columns, and use PNP or P-channel MOSFET to source current to the layers.
pawillems:
I am building a 4x4x4 led cube and going to control it by an Arduino Uno. Each column in the cube shares its anode and each layer shares their anodes.
One of those should say "cathode"....
pawillems:
However, in the instructable each layer is routed directly to a pin on the Arduino.
Instructables aren't known for doing anything correctly.
(Quite the opposite from what I've seen - 16 LEDs on an Arduino pin doesn't surprise me in the least.
pawillems:
If at some point a layer is fully lit it would need to sink 160 mA, well above the limit of 40mA per pin. So to my understanding I will ruin the Arduino if I built my circuit this way.
Yep.
Even if the Arduino survives ... the LED brightness will vary depending on how many are switched on so it will look horrible.
pawillems:
My solution to this would be to use transistors for each layers. Connecting the base of the transistor to one of the pins of the Arduino and the other pins of the transistor to the layer of the led cube and the ground of the Arduino respectively.
Good.
You may have to use PNP transistors depending on where your anodes are.
Thanks for the replies! Just to inform you guys how I ended this project; I used some NPN transistors (rated for 1A) to control the sink of each layer.
In reply of some other remarks made. A 4x4x4 cube is controllable without using shift registers and just all the pins of the Uno. I didn't like to complicate stuff, so I did not use them. Of course it would be a nice practise if one would like to scale up to 8x8x8 or any larger.