Electronic – arduino – Multiplexing an 8×8 Matrix – Why Transistors

arduinoledmultiplexer

I'm trying to understand how to properly multiplex an 8×8 matrix (or any large amount of LEDs)
http://arduino.cc/en/Tutorial/RowColumnScanning

However, I'm getting a bit confused, since I've found others like this: http://garagelab.com/profiles/blogs/arduino-scrolling-text-marquee-to-give-a-happy-christmas

That one says to use transistors for the current switching, but the first link doesn't even use any resistors (which I find suspect), nevermind transistors.

I don't really see why the transistors are needed, can anyone explain why?

Thoughts?

Best Answer

The transistors are needed if the current required to drive the LEDs is higher than the microcontroller can handle. This means either a single pin current rating, or the maximum rating for all the pins together (will be given in the datasheet)

Most typical 5mm and 3mm LEDS have a maximum current rating of around 20mA and can be driven directly from a microcontroller pin (10mA is fine for most applications)
However, if your microcontrollers maximum rated current is 200mA and you want to drive 20 LEDs at 15mA, then even though the individual pins can supply the current you are out of spec for the maximum current rating.

The LEDs should always have a current limiting component (e.g. resistor) in place when driven from a voltage source, so you are right to suspect the first link. It appears that it is simply relying on the pins drive not being high enough to cause damage to the micro or the LED, which is definitely not a good idea.

Here are the the Absolute Maximum Ratings for the ATmega328. Notice there is a per pin current rating and also a maximum total Vcc current rating:

Max Specs

Also see notes 3 and 4 on pg.314:

Notes

Also, you can get high power LEDs with current ratings of >500mA, so a transistor is obviously the only option in this case.