I’m working on a white LED matrix project (8×8). The wiring is (see image on the end):
Rows are driven directly from MCU pins (set high for the active row).
Columns are switched to low through NPN transistors.
The bases of the transistors are also driven directly from MCU pins (with base resistor like diagram below).
One row is active at a time, and the MCU cycles through the rows for multiplexing.
If each LED is set up for 20 mA when lit, then when one row is active and all 8 columns are switched on, it seems like:
The MCU pin driving the row would have to source 8 × 20 mA = 160 mA instantaneous current.
The column MCU pins are only providing base current to the NPN transistors, not LED current.
I understand that with 8 rows, each LED is only on for 1/8 of the time, so the average current per LED is much lower (~2.5 mA average), and the average per row pin is also lower. But this doesn’t change the fact that at a given instant, all 8 LEDs in the active row would try to draw their full current, right?
My questions are:
Am I correct that the instantaneous current from the row pin is the sum of all the active LEDs in that row?
If yes, how can MCUs like Arduino (ATmega328P) or STM32 safely drive such a row directly without external high-side transistors, since 160 mA instantaneous is way above their per-pin limits?
Is the solution simply to use higher resistor values so that the per-LED current is much lower than 20 mA, keeping the total instantaneous current within the per-pin limit?
I saw a bunch of forum questions where @PaulRB answered (probably who I'm looking for to help ) but I still couldn't understand.
If I take an extreme example, if I draw from the MCU pin 1A for 1 second and leave it for 20 seconds off, the average current would be 0,05A (1/20) but that would still burn it. So the only thing that makes sense to me is if there's an "maximum time" where we can overload the MCU output pin with more current that it can handle, for instance 1ms - then it doesn't burn. Is that it?
I’ll attach a reference schematic (only reference, the trasnsistor are incorrect if considering NPN) of the matrix with transistors on the columns.
That will damage port pins. Always use current limiting base resistors, like 470R or higher as shown in the posted schematic.
Yes. Current adds.
Use transistors to switch the current, or use multiplexing to limit the number of LEDs that are on at any one time. No more than 20 mA per port pin, in or out.
That is one solution, but the result may not be bright enough.
Yes, I'm using base resistors (see diagram in the end of the post) but my question is more on the pins that are directly on the led. More about the instantaneous vs average current
NPN transistors will work with red and green LEDs in that configuration, because the base turn on voltage will typically be less than 2.7V (with one LED as emitter load).
The modern choice for LED matrices is a dedicated chip, such as the MAX7219 or HT16K33, which do all the dirty work.
If you want to save yourself a lot of expense and work, use WS28xx addressable RGB pixel led strings. You feed them 5V or 12V depending on type from a PSU and data from the duino, X many lights with 16M colors... 256 shades of white included.
WS2811 encases the leds in 8mm diffuser bulbs (in 12mm body) that glow color. The wires between bulbs are like jumpers, easy to splice, and a string of 50 cost $16 + ship (Amazon, Alitove WS2811). All the bits assembled, can chain or split off as many strings as you can power. 50 can be chopped into 5 10-led strings, etc.
Human eyes take a while to see numbers or text well, like 250 ms minimum which leaves plenty of cycles for filling a FastLed library LED array with the next change, triggered by the LED.show() function on time. You can make 100's of lights appear to move (change every 40ms) without needing to solder more than few connections.
Every 40ms is 25 frames per second, faster than the human eye 24FPS=motion on film.
Amazing, 10 strings for $129. That's 25.8 cents per bulb.
Higher than what? Your diagram does not show any current limiting resistors for the LEDs.
If you added the missing current limiting resistors for the LEDs, with sufficiently high value, yes, that would prevent damage to any of the components, but it would also reduce the brightness of the matrix. That can be avoided if you scan by column. You will still need current limiting resistors for the LEDs, but they can be of lower value, for example 220R rather than the ~1K that would be needed if you scan by row.
Maybe there is such a limit, but it's not mentioned in the ATmega328 data sheet, only a single limit is stated, so you have to assume it's an instantaneous limit. You exceed that limit at your own risk.
1ms is a very short period for a human, but it's a long time for an MCU, and damage might well occur if the pin current limit was exceeded for that long.
The forum can only comment on the schematic you post, not a different schematic that's in your head. However hard you try to describe the circuit in your head, English isn't a great way to do it.
Why not post a schematic of your proposed circuit? Hand-drawn is fine so long as it is neat enough to read clearly. It doesn't even have to show all 8 rows or columns, maybe just the first and last row and first and last column, with comments indicating that the other rows and columns follow the same pattern as those shown.