Go Down

Topic: Pulling my hair out trying to drive this led array (Read 2721 times) previous topic - next topic


Hey guys,

So, as I mentioned the other day, I'm trying to drive four green 20 segment bar graphs from an Arduino Pro Mini, in a manner not unlike a vu meter.

My experiments with a 10 segment LED bar graph have led me to determine that powering the equivalent of eight of them directly from the Arduino's pins isn't going to work.

For my first experiment, I wanted to see how bright my LED's would be if I lit them one at a time with 20mA of current.  I calculated that with this setup, to update the entire array of 80 leds 60 times a second, I would need to keep each led lit for 208 microseconds. Unfortunately, the results if this experiment were less than stellar, and I ended up with an extremely dim array.

My next experiment was to see how the array would look if I split it into eight groups of 10 leds, and lit 10 leds at a time, putting 15mA of current through each for 2083 microseconds, again for a 60hz refresh of the display.  This would require a total of 150mA of current, which the Arduino can supply, but not sink on a single pin, so I would have one transistor per group of leds through which I would sink that current safely.  That was the plan anyway.  But this test was also a bit of a let down.  The array ended up being only half as bright as I'd like it to be.

At this point, I'm not sure what would be the best direction to go with this.  

One option, I think, would be to use two sets of tansistors, one for the rows, and one for the columns, to source and sink the current.  (Do I need to use two different types of transistor to do this?)  But that option is unappealing because it would require way too much soldering. The last time I tried to solder 18 transistors point to point the resulting board was a mess and didn't work and I never figured out where the problem was.

The other option I have is to use a few IC's to drive the leds somehow.  I'm not sure what the best option for this would be though.

Using a 4017 looks like it's right out.  If I'm lighting the leds one by one, I'd have to pulse them with 120mA of current just to get them to the point I'm at now where I'm putting 15mA through 10 of them at once.  And I'm certain the 4017 can't deliver that kind of current.  I'm not even sure it can deliver 10mA.

I've also looked at the 74HC595 shift register.  I'm not sure if it's best suited to this task though, or if it could handle even the 200mA needed to drive 10 leds at a time at 20mA each, nevermind the 400mA I'd like to put through it to pulse the led's to be brighter since I'd still be multiplexing them and running them 1/8th of the time.  Also, since they only have 8 bits, I'd need two if I were to put them on the rows, and three if I have to put them on both the rows and columns.  (And I don't even know if they can sink current.)

Then there's this that caught my interest just now.  I wondered if there might be an IC which just has a bunch of transistors in it to make my life easier when wiring them up, and I came across something called a darlington transistor array.

Here's one I found which has eight inputs and outputs:

I don't understand why these have two transistors for each pin, unless that just allows them to amplify the voltage more.  I also don't know if they can both source and sink current.

But if they can both source and sink current, and they're set up to work like a switch that I can just turn on and off by applying voltage to the right pin, then these seem like they'd make wiring up my array really simple.  I could just solder them up against each edge of the array and bridge the gap between the pins, (or maybe stick some resistors between if needed) and no crazy mess with 18 individual transistors with pins that have to be bent funny to get them to fit the holes in the perfboard.

Anyway, let me know what you think.  I'd be really happy to hear that I can simply stick a few of those ULN2803A transistor arrays on there with a few resistors on the rows so I can get away with cylcing through 80 leds 10 at a time, and put 40mA through each of them this way.

Ran Talbott

I don't understand why these have two transistors for each pin, unless that just allows them to amplify the voltage more.

Close:  it's to amplify the current.  The first transistor takes a small number of microamps and amplifies that to a small number of milliamps,  and the second amplifies that to lots of milliamps.  It's called a "Darlington",  if you'd like to google for the details.

You're right to be suspicious of the 74HC595:  some people abuse it for driving LEDs,  but it doesn't have the current capacity to do so safely.  You could use them to expand the number of output-only pins for driving ULN2803s,  though.  There are also shift registers like the TPIC6C595 that are relatively cheap and can drive LEDs directly.

You do need different kinds of transistors to drive the positive side if you're going to multiplex the displays,  usually a PNP transistor or P-channel FET.  There are some "high-side driver" chips out there,  but there's never been a "de facto standard" among hobbyists for those like there is for using ULN2xxx chips for low-side drivers.


What about a decoder?  I saw those while researching various chips as well.  Is there some kind of 8-bit decoder I could use to sink large amounts of current?

Wait, you said I need different kinds of transistors on the positive side...

Could you explain why I need different kinds of transistors?  My understanding is that voltage goes in one side, and comes out the other if you apply voltage to the base pin.  In that way the transistor acts like a switch.  

So why can't I just connect the rows and colums to one side or the other of that transistor?  Ie, conect the output of one group of transistors to the rows, with the input going to Vcc, and the input of another group of identical transitors to the columns, to pull them down, with the output going to ground?

What am I missing here?


No that's fine, it will work (with all identical NPN transistors) - the transistors connected to ground sink current and will act as inverters (common emitter) and the high-side transistors are emitter-followers (current amplification only).  Just be careful not to over-drive the LEDs and burn them out - resistors also needed on bases of the ground-side transistors.

Worth trying to find out the pulsed current rating for the LEDs - often a device that's rated at, say 20mA, is spec'd to handle higher current pulses at a low duty cycle.
[ I won't respond to messages, use the forum please ]


Mar 06, 2010, 05:00 am Last Edit: Mar 06, 2010, 05:01 am by scswift Reason: 1
Again, I'm lost.

Mark says using all NPN's is fine.  Rant says I need PNPs to source current.  (Isn't the ULN2803 supposed to source current?)

Which is correct?  And why?

And can I use ULN2803s to both source and sink current? (<- This is what I really need to know!)

As for the pulsed current rating on the LED's, here's the datasheet for the arrays I'll be using:

It seems to indicate that I can pulse them with a maximum of 140mA of current if I am multiplexing 10 leds and pulsing each one for only 100 microseconds, which is like updating the display at 1000hz.

Hm.  I wonder if that 0.1ms is a typo.  I wish these data sheets had more data.  I mean how am I supposed to figure out what other values are safe to pulse at?  I mean if I extrapolate linearly, I might assume I can pulse 70mA for only 0.2ms, or 35 for only 0.4ms and that can't be right.  And is linear extrapolation even the correct way to go about it?  I wish there was a graph!  Though 35 for 0.4s would kind of make sense which lends credence to 0.1ms being a typo.

Hm... Maybe I should look at some of theoir other bargraph datasheets to see if those state something different...  

...well crap.  All their datasheets for the bargraphs use the same template, and say the same thing.  I'd hoped there might be an older one sitting around.


Okay, so I've done some more research and it looks like the ULN803 can only sink current.

For some reason, just to confuse me, the datasheet labels one set of pins the inputs, and the other the outputs, even though ultimately both sides will have current flowing into them with the ground pin being the only output:

But regardless, now that I understand that, looking at the schematic, I can see why the chip cannot source current... there's only one output.

If I was using individual NPN transistors, I could either attach their outputs (emitters) to the anodes, or their inputs (collectors) to the cathodes, depending on whether I was trying to source or sink the rows and columns.

But with this chip, there's only one common emitter, and a bunch of collectors (and bases).  So there's no way to connect the emitters from each of the individual transsitors in the chip up to the anodes of my leds.


So where does that leave me?  Well, I guess like Ran said, I either need some kind of "high side drvier" chip, or I need to use individual transistors to source current to the anodes of my leds.

Only problem is, I don't know what sort of high side driver chip I could use.  I guess I should look at the specs of that shift register, but Ran has indicated it won't source enough current.

The other thing I'm confused about is why Ran said I need PNP transistors to source the current.  I wasn't aware there was any difference between PNP and NPN besides the chemistry of the inner workings of the thing.  Does it really make a difference, and why?


Mar 07, 2010, 04:09 pm Last Edit: Mar 07, 2010, 04:12 pm by scswift Reason: 1
Okay, I think I've found a suitable high side driver chip:

The part number looks similar to the ULN2803 which makes me think it's some kind of standard chip made by multiple manufacturers, but so far I've only been able to find these ones made by Allegro.  That kinda sucks because I was hoping to find something I could order from Mouser, since I'm going to be ordering a bunch of parts from them soon and I generally use them as my supplier.  (Mouser sends me catalogs and calculates shipping for me.  Newark does not!)

The two variations of that chip there have eight inputs and outputs.  I can't figure out what the difference is between the 81 and 82 models are though.  (I see the stats are different, but I don't understand what that difference means.)  I think either will work though.  I hope so.

If anyone knows of a similar chip that I can get from Mouser, please let me know.  It'll save me like $12 on shipping.


Ah, I think it is some kind of standard chip.  Here's another manufacturer who makes a 2981:


Hm...  now that I'm starting to understand this source/sink thing, I'm wondering if I could pair a couple of these:

With one of these:

...to multiplex four 20 segment bargraphs.

It looks like the 3914 doesn't do its own multiplexing, so that wou;dn't interfere with things.  But I don't know how fast it would respond to voltage changes as I multiplex the four displays.  Hm.  Perhaps this is a bad idea.


Mar 08, 2010, 06:32 pm Last Edit: Mar 08, 2010, 06:35 pm by Grumpy_Mike Reason: 1
Perhaps this is a bad idea.

I think so. The LM3914 has a built in analogue to digital converter so it takes an analogue signal in. If you want to use one and multiplex it with the 2981 you will have to arrange to also multiplex the analogue input at the same time. This will involve using a 4051 (or 4052) analogue multiplexer. It is just too messy and doesn't get you anywhere.

I wasn't aware there was any difference between PNP and NPN besides the chemistry of the inner workings of the thing.  Does it really make a difference, and why?

Yes it does. A PNP is an upside down NPN transistor. Emitters go to +ve not ground and collectors go to ground not +ve.
To turn it on you need a difference in voltage between the emitter (now at +) and the base. So you turn it on with a logic low and off with a logic high. Exactly the opposite of an NPN.


Yes it does. A PNP is an upside down NPN transistor. Emitters go to +ve not ground and collectors go to ground not +ve.
To turn it on you need a difference in voltage between the emitter (now at +) and the base. So you turn it on with a logic low and off with a logic high. Exactly the opposite of an NPN.

Okay, but why did Ran say I needed to use PNP transistors to source the current?  I don't get that.

I do see that on this page:

For the NPN circuit, they show the load on the positive side:

And for the PNP they show the load on the negative side:

But does that matter?  And why?  I was under the impression that you could generally stick a resistor anywhere in your circuit.  Ie, before or after a LED, and the result would be the same.

And now I'm looking at this page:

And it's got this schematic:

Which seems to indicate an NPN can source or sink, but now I'm even more confused.  Why can it only source OR sink?   And why does the text above the diagram and the schematic seem to indicate that RL isn't the load at all, but rather a pull up or pull down resistor, and that red line is actually coming from the real load?

Hm... the diagrams on this page are clear at least:

That's easy enough to understand.  Too easy.  I am suspicious of it.


Mar 08, 2010, 08:35 pm Last Edit: Mar 08, 2010, 08:37 pm by scswift Reason: 1
Okay maybe this will clear things up a bit.

This is my current understanding of how a transistor works:

I forgot to indicate it, but I would set the pin with the 1K resistor high  to turn the transistor on.

Now, is this right or wrong?  I don't see why both leds shouldn't light, assuming V+ is 5v and that pin is set high.


Oh, and pretend I put that 220 ohm resistor on the branch with Led1, not where it would affect the current going into the Arduino.  


Mar 08, 2010, 11:49 pm Last Edit: Mar 08, 2010, 11:51 pm by Grumpy_Mike Reason: 1
but why did Ran say I needed to use PNP transistors to source the current?  I don't get that.

The two circuits under this quote are indeed the same from the point of view of a simple load.
However, the emitter to collector is the switch, so to source current it needs to come from the positive, so that means a PNP. To sink current you need to connect the negative line and that means an NPN.

In other words you can only source current through the collector resistor with an NPN. You are trying to drive a matrix which means you have a collection of current sources (for the rows) and sinks (for the columns). This normally means using both types of transistor.
In that last drawing the LED in the emitter is receiving sourced current BUT the voltage you can achieve for the source is only 0.7V less than the voltage on the base. There is no voltage gain in this configuration (common collector or emitter follower). With a PNP sourcing the current the transistor can be turned fully on with the rail to rail signals from the digital outputs.

Why can it only source OR sink?

Because a transistor is a simple on / off switch, to source and sink you need two transistors to make a change over switch.


In that last drawing the LED in the emitter is receiving sourced current BUT the voltage you can achieve for the source is only 0.7V less than the voltage on the base.

I'm still completely lost.

Let's say LED2 wasn't there.  That it was just replaced with a wire.  In that case, when I set the pin attached to the base high, won't that LED light, with 15mA, assuming V+ is 5v and the forward voltage of the led is 2.1?

That is how an NPN transistor is supposed to be wired to be a switch, isn't it?

Now add LED2 back into the equation.  What's different?  Why will LED1 get 15mA and 5v, but LED2 will only get...


BUT the voltage you can achieve for the source is only 0.7V less than the voltage on the base.

What does that mean?  Achieve less voltage?  Ugh.  I've seen negative voltage in some IC data sheets, which I believe was how they implied that a pin was sourcing current... but that doesn't seem to be what you're saying here.  Why would I WANT more than a drop of 0.7v?  And what source exactly are you referring to?  The emitter?

There is no voltage gain in this configuration

I'm not trying to increase voltage.   I want to increase the current... don't I?  

My problem is the Arduino can only put out 200mA at most.  And each pin can only source or sink 40mA at most.  I have eight arrays of 10 leds.  So I have 10 rows, and 8 columns.  If I connect one pin to each row, I have plenty of voltage, but I can only put out maybe 15mA per pin if I want to try to keep the Arduino's total around 150mA.  Then I have to divide that 15mA by eight since I'm multiplexing the columns.  That leaves me with less than 2mA on average per led.  So the solution is to use one transisor per row to source more than 15mA to each of those leds, to bring that average up.  Problem is, even if I only had that 15mA per led, that would still put me over, because the pins on the columns can only sink 40mA.  So, I need transistors on both the rows and the columns so that I can source 40mA or more to each led 1/8th of the time, and sink 400mA or more in each column 1/8th of the time.  (And if I recall correctly, the chips I bought can only handle 500mA, so it was perhaps a wise decision to buy those bar graphs which are twice as bright as the original ones I was using along with them today.)  At no point that I know of does a need for a voltage gain here, since it's all running in parralel.

But maybe you're referring to something else I don't understand.


Mar 09, 2010, 10:16 am Last Edit: Mar 09, 2010, 10:18 am by Grumpy_Mike Reason: 1
At no point that I know of does a need for a voltage gain here,

Voltage gain in a transistor is the fact you can switch the transistor fully on with only 0.7V, that is what you do. Yes you feed it with a 5V signal but you have a resistor in series to limit the current to safe values and you only "use" 0.7V of the 5V output. You have and need voltage gain.

In the common collector circuit (the one with the load in the emitter) you have no voltage gain. So a load being switched in this arrangement (load in the emitter) can only have a voltage on it that is 0.7V less than the voltage from the digital output. This is a nominal 5V but can be as low as 4.2V according to the data sheet of the processor. This means you can only get a voltage of 3.5V across the load. This might be enough if you are limiting the current to an LED with a resistor but it increases the power dissipation of the transistor because there is more voltage dropped across it. If you are then driving a current sink you loose even more voltage. You can do it but it is a bad design because it gets too hot and has a limited output voltage.

In your application you need both source and sink current capabilities above the raw pin output.
Therefore you need to sink current, with an NPN and source it with a PNP, or the equivalent FETs. The high sided driver you found will work fine, you will find it has PNP transistors or P-channel FETs in it to make it work.

A few specific points:-
Why would I WANT more than a drop of 0.7v

You don't so don't use an NPN for sourcing current.

And what source exactly are you referring to?  The emitter?

No the collector is the source of current in a PNP and the sink of current in a NPN. The emitter always goes to the rail you are trying to switch to. Use a PNP to switch to a positive rail and an NPN to switch to a negative or ground rail.


Hm...  I think I'm starting to undertsand now.

I've just drawn up a schematic.  I was thinking I'd just set the rows and columns to be high to turn on their respective transistors.  But that's not how I would have wired the circuit if I didn't have the transistors there, is it?  I'd pull those columns low.

And looking at my shchematic, that means that on my columns, the negative terminal of my leds needs to go to ground.

Now I could stick an NPN transistor there, but that would mean connecting the collector to the led.  And since the led has caused a voltage drop, that means the voltage at the collector is going to be less than 5v.

And... still having trouble wrapping my brain around this...  I think that would affect the ratio between the voltages on the collector and base.  

But if I use a PNP there, then instead of setting the base high, I pull it low.  And the emitter is connected to the negative side of the led.  So the base to collector ratio...  

Mmm... I'm lost again.  I need to read up more on these.

Thank goodness I bought those driver and darlington IC's, I think those are gonna make my life a lot easier.  I gotta get this thing up and running and shipped to people by the end of this month.  I thought using the Arduino was gonna make my life easier, and it would, but then I had to go and offer something way more sophisticated than what I originally planned. :-)

Go Up