Multiplexing - Too dim.  Need help!

Okay, here's my problem:

I'm using a 5v Arduino Pro Mini, and I need to multiplex four 20 segment led bargraphs in a manner which is to resemble a vu-meter.

In addition, I need to power a piezo speaker for sound, and two illuminated pushbuttons. The pushbuttons can be powered directly from the battery, so they probably don't need to be considered, but the piezo will need to be, and I have no idea how much current it uses. (Though I can provide spec sheets for it.)

I've just got done experimenting for the evening with a 10 segment LED bargraph, and I discovered I had a problem. When multiplexing just those 10 led's, the display far was too dim.

Reading that, I determined that I could improve the brightness of my display two ways.

The first was that since I wasn't using a 100% duty cycle for my LED's, I could pulse them at higher than 20mA. I could in fact, probably pulse them safely at the max output for a single pin on the Arduino: 40mA.

The second was that rather than flip each LED on and off as fast as possible and, it might be better to only update the display 60 times a second. So, dividing 1000 by 60, and then dividing that by the number of leds in the array, which is 10, I determined I should keep each led on for around 1.6 milliseconds, or 1600 microseconds. (I later changed this to 1400 so the display would be updated 70 times a second because I can detect a 60hz flicker) And I guess this allowed the LED enough time to illuminate properly because it certainly helped, effectively doubling the percieved brightness of the display.

Here's the code for the multiplexing btw:

``````void setup()   {

for (int x = 2; x < 12; x++)
{
pinMode(x, OUTPUT);
}

}

void loop()
{

for (int x = 2; x < 12; x++)
{
digitalWrite(x, HIGH);
delayMicroseconds(1400);
digitalWrite(x, LOW);
}

}
``````

Still, even with these two modifications, the 10 segment display was only just bright enough to be acceptable. It dawned on me that I had to run like eight of these things in order to build the display I needed. How on earth was I going to get those to be bright enough?

I thought maybe I could light more than one led at once? But to get the same brightness, I'd have to light eight of them. And if I'm running each one right now at a peak of 40mA, then having eight would require 320mA, and though the Pro Mini 5v specs say it can can source a total of only 200mA. So divide 200 by 8, and that's 25mA. Meaning, I'm almost back where I started. IF I could figure out how to wire those 80 led's so I could light 8 at once, I'd still be left with a display which is fairly dim and unimpressive. Maybe even too dim to see in the daylight.

So, I need another way. The easy route doesn't look like it's gonna work. I either need to use some kind of bargraph driver IC, or several 4017 decade counters, or several 4015 dual shift registers, or maybe I might be able to get away with just a handful of transistors.

So what would be the easiest route to go here? Keep in mind I'm gonna have to solder all this by hand onto perfboard, I'm gonna have to build several of them, and I'd really rather not have to build something that needs four IC's to work.

I'm thinking sticking some transistors onto the rows and columns is gonna be the easiest route to go. Not sure how to wire that up though. It needs to be done in a way that would allow me to light at least 8 leds at once and put 40ma through each of them.

I gotta run, so I cant give a very detailed answer right now.

Basically I don't get why you do it like that in your test, unless it's just a test. If you can use all the pins simultaneously, do that. Oh, and never go above the specs for the arduino, I'm not sure that is safe. Google/search this forum for using a transistor, if you need more current.

4 20-segment LED bargraph. I reckon you could split that up into 8 10-segments, using the Arduino directly you could in fact get away with using 8 outputs as multiplexing, and 10 outputs for the LED's (eight segments in parallell), thus having 1/8th duty cycle for each segment. But leaving no pins left for buttons and the piezo.. Better to use a shiftregister (or two-three in your case), and save some pins, and better yet, combine it with a 3-to-8 line demultiplexer (or even yet another shiftregister, with latch, making sure only one pin at a time is active).

This was probably a very quick and confusing answer.. I'lll get back to you unless someone else does. It would probably help if you posted more details on the wiring/hardware.

Basically I don't get why you do it like that in your test, unless it's just a test. If you can use all the pins simultaneously, do that.

It was a test. I did it to learn how to do multiplexing, to debug, and to see how bright 10 leds in a bargraph would be when multiplexed.

(Also, I had them set up as a common cathode, so there was only a single 82 ohm resistor, and I didn't know what effect turning on multiple pins would have in that circumstance, and didn't want to risk blowing anything up.)

4 20-segment LED bargraph. I reckon you could split that up into 8 10-segments, using the Arduino directly you could in fact get away with using 8 outputs as multiplexing, and 10 outputs for the LED's (eight segments in parallell), thus having 1/8th duty cycle for each segment. But leaving no pins left for buttons and the piezo.

If I were to put 10 pins into each of those displays, and have one pin coming out of each, then in theory I could source 40ma to each LED. (Though of course I'd keep this to a more reasonable 20ma) But the return pin can only sink 40ma. So that means in reality, I'm limited to just 4ma per LED in each of those arrays.

Right now, I have a 10 segment bargraph. I am putting 40ma into each LED, but only for 1/10th of the time. That is an average of 4ma per LED. However, due to human perception, as outlined here:
http://www.piclist.com/techref/io/led/pulse.htm

Putting 40ma through for 1/10th of the time will actually appear twice as bright as running 4ma through 100% of the time.

So... If I were to do what you suggest, the numbers say that each of those 10 led bargraphs would be half as bright as the one I am now multiplexing, even though the led's will be run at a 100% duty cycle, because I can't run each led in that array at more than 4ma or I'll burn out the pin they're returning current to.

In short, it won't work.

But if it did work... or if it could be made to work... it might work.

What I mean is, if I COULD source 20ma to each of those led's in that array, and multiplex the 8 10 led bargraphs with a 1.8 duty cycle... they'd be plenty bright.

I can't do that though because the Arduino can't put out a total of more than 200ma though and I still gotta run that piezo.

But 10-15ma per LED... That'd still be brighter than what I was getting in my multiplexing test. That would be bright enough.

So what if... I set up each of those bargraphs to be common cathode, and then I stuck a transistor off that common cathode. And then instead of having the cathod return to one of my arduino pins, it went to ground, and I switched the transistor with the return pin instead?

Then the output pins could source their 15mA of current, and that would get sunk by ground, which can handle 150mA, instead of another pin, which can't. And I'll have 50mA left over for my piezo, which I assume it plenty to run it, but again I don't really know for sure.

That'll require 18 pins for the array, and one for the piezo. I soldered machine pins onto my Ardino Pro Minis so I can detach them from the circuit to program them, which gives me access to all 14 digital pins, plus the 6 analog pins, so I'd have enough pins for LED's and piezo. And only one of the switches needs to be on a pin, so that makes 20. I should have enough...

What I need to know now though is if a transistor can source that 150mA for the array. I assume it can, since I've seen them used to light incandecent bulbs. Oh, and I need to figure out how to work the things. I guess just setting the pin high will be enough to put it full on?

What I need to know now though is if a transistor can source that 150mA for the array.

yes if your using a npn type a 3904 can pass ~200ma and a 2222 ~600ma

pnp type 2907 is the equivalent of a 2222

Hm... I've got a bunch of these:

But I'm guessing those aren't suitable, by that 100mA peak colelctor current there. Can't find the datasheet either.

So I suppose I should pick up one of these:
http://www.mouser.com/Semiconductors/Transistors/Bipolar-Transistors/_/N-2xpqh?P=1z0z60l&Keyword=2222+npn+transistor&FS=True&Ns=Pricing|0

Not sure which to get though. Should I get one with an emitter base voltage of 5v, or does that not matter?

(Also, I had them set up as a common cathode, so there was only a single 82 ohm resistor, and I didn't know what effect turning on multiple pins would have in that circumstance, and didn't want to risk blowing anything up.)

Other than that I think your resistor is way too low, I don't think turning multiple pins on would matter much in terms of total current output (correct me if I'm wrong) in this case. In ideal LEDs with the exact same specs it would be exactly the same, same voltage drop over the resistor (and hence current). But that's not the case, however the difference isn't much. But the LED's probably would be differently lit due to them not being exactly alike. (This is generall not the way of using one resistor for multiple LEDs. Unless only one is on at a time).

According absolute maximum ratings on the Atmega's (page 316 of this document: Smart | Connected | Secure | Microchip Technology, found here: Smart | Connected | Secure | Microchip Technology):

28.1Absolute Maximum Ratings*

Operating Temperature..................................-55°C to +125°C
Storage Temperature.....................................-65°C to +150°C
Voltage on any Pin except RESET
with respect to Ground................................-0.5V to VCC+0.5V
Voltage on RESET with respect to Ground......-0.5V to +13.0V
Maximum Operating Voltage............................................6.0V
DC Current per I/O Pin...............................................40.0 mA
DC Current VCC and GND Pins................................200.0 mA

*NOTICE:Stresses beyond those listed under “Absolute
Maximum Ratings” may cause permanent dam-
age to the device. This is a stress rating only and
functional operation of the device at these or
other conditions beyond those indicated in the
operational sections of this specification is not
implied. Exposure to absolute maximum rating
conditions for extended periods may affect
device reliability.

So I wouldn't really go near 40mA on any pin. 82 ohm seems borderline. I don't know your LEDs voltage. Though it is pulsed, I'd think a maximum is a maximum. At least I'd be careful with your Arduino, but hey it's your Arduino

However, due to human perception, as outlined here:
Pulsing LEDs for effeciency, brighter appearance and multiplexed display

Putting 40ma through for 1/10th of the time will actually appear twice as bright as running 4ma through 100% of the time.

Thanks, thats interesting. I didn't know that.

But if it did work... or if it could be made to work... it might work.

What I mean is, if I COULD source 20ma to each of those led's in that array, and multiplex the 8 10 led bargraphs with a 1.8 duty cycle... they'd be plenty bright.

I can't do that though because the Arduino can't put out a total of more than 200ma though and I still gotta run that piezo.

But 10-15ma per LED... That'd still be brighter than what I was getting in my multiplexing test. That would be bright enough.

So what if... I set up each of those bargraphs to be common cathode, and then I stuck a transistor off that common cathode. And then instead of having the cathod return to one of my arduino pins, it went to ground, and I switched the transistor with the return pin instead?

Except as stated, don't use one resistor for mutliple LEDs that are on simultansously, then that's one way of doing it, yes. Use one resistor pr. LED. Then gang the common cathodes together to a transistor, for instance.

Oh, and I need to figure out how to work the things. I guess just setting the pin high will be enough to put it full on?

If it is an NPN transistor, and with a resistor to the base, yes. Don't connect them directly! Bipolars are current controlled (as opposed to FET's, which are voltage controlled), so you kind of need to know what currents to expect. But for an on-off application I guess it's okay to saturate the transistor (making sure it's fully on when on, without damaging it of course), so the base resistor value is not too critical. say 1k - 10k. Depending on the transistor's specs, important one being hFE (and of course current/voltage ratings). hFE.

Here's a quick page about transistors in general: Transistor Circuits

Forgot one thing:

That'll require 18 pins for the array, and one for the piezo. I soldered machine pins onto my Ardino Pro Minis so I can detach them from the circuit to program them, which gives me access to all 14 digital pins, plus the 6 analog pins, so I'd have enough pins for LED's and piezo. And only one of the switches needs to be on a pin, so that makes 20. I should have enough...

I'd be careful about using Arduino pins 0 and 1, as they also are used for uploading sketches. It might work as long as you don't use those for interrupts I guess. And wire them with the thing in mind that they are also serial I/O. But I'm a bit uncertain about this. So far I've just avoided using those

I've spoken with a few folks here about using those pins, and the consensus seems to be that it's only a problem if you've actually got stuff hooked up to them that might draw a current or introduce noise while you're trying to upload.

To circumvent that issue, I've mounted my Arduino Pro Minis on machine pins so that I can remove them from the circuit while programming:

Btw, those machine pins kinda suck. I bought em from sparkfun, and they're supposed to be breakaway, but every other time I broke one off, half the plastic sheared away from the body of the pin, exposing it. I didn't have that problem with their breakaway headers, but those are fairly long and while they'll seat in an IC socket, they leave a pretty big gap beneath the arduino, and the sides of the pins are left exposed.

Anyway, in regards to interrupts, I don't know anything about those. I'm still learning how to code this thing. Nobody's mentioned any potential issues with those to me though.

Oh, and I'm still wondering which of these transistors would do the job for me:
http://www.mouser.com/Semiconductors/Transistors/Bipolar-Transistors/_/N-2xpqh?P=1z0z60l&Keyword=2222+npn+transistor&FS=True&Ns=Pricing|0

I don't know whether I need a 6v or 5v one, or if that matters, or what makes those different from one another.

Those transistors look OK.

I don't know whether I need a 6v or 5v one

Those are only the base to emitter breakdown voltage, when you use the transistor to switch an LED on this will be at 1.2V tops so it doesn't matter.

Btw, those machine pins kinda suck. I bought em from sparkfun

yep, I got some of those, paid nearly 3x the price and have nothing but trouble out of them, breaking it away always leaves a half pin exposed and shoving anything into them is a real chore

and that is with 22guage round wire or component leads, forget about their crappy jumper pins they just fold up in those things

my advice, avoid sparkfun, expensive + crappy = meh

Those are only the base to emitter breakdown voltage, when you use the transistor to switch an LED on this will be at 1.2V tops so it doesn't matter.

Perhaps, but it's not like the only thing I'm ever gonna run with a transistor is an LED. Maybe in this case it doesn't matter, but I want to know how to use the things properly. I will probably need to run a motor or a speaker off one at some point in the near future. So, in that case, if it's not gonna cost me a bunch more, I'd like to get the more robust model because I'll be getting spares and then I'll have what I need at hand for whatever the purpouse.

Anyway, after pulling my hair out and trying to understand that page on transistors, and figuring out that I could get rid of 2/3rd of the results by just looking at the ones available in a bulk pack, and determining that Fairchild was quite a bit cheaper than On and they're probably just as good as one another, I was able to whittle the list down to the following:

http://www.mouser.com/Semiconductors/Transistors/Bipolar-Transistors/_/N-2xpqhZscv7?P=1z0z60lZ1z1414h&Keyword=2222+npn+transistor+fairchild&Ns=Pricing|0&FS=True

And from that list, I selected the PN2222ABU, because the datasheet for it is newer than the PN2222BU, the specs look better,
and the PN2222ANLBU appears identical to it in every way, but four cents more for reasons I cannot fathom. Also Mouser's got 60,000 of the PN2222ABU on order, so I know they're not planning to phase it out anytime soon.

Perhaps, but it's not like the only thing I'm ever gonna run with a transistor is an LED.

Yes but if all you ever do is to use the transistor in common emitter or common collector mode there is no way you can exceed this figure. A transistor will turn on and not exceed the Vbe. If however you only wire two of the leads up then you could exceed the figure and the junction will break down. This in itself is reversible.