LED matrixing current question

Hi there, I am about to start working on a Arduino Due project, I haven't wired it up yet but I have the hardware planned. I was looking over the Due product page on the main Arduino website and spotted this:

Each of the 54 digital pins on the Due can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 3.3 volts. Each pin can provide (source) a current of 3 mA or 15 mA, depending on the pin, or receive (sink) a current of 6 mA or 9 mA, depending on the pin.

My question is this, I have 16 LEDs arranged in two rows of eight, I was hoping to use 8 digital pins to source current and 2 to sink current to control the two rows. I would hope that I can have up to 8 LEDs on at a given point in time, meaning 8 pins sourcing current through an LED to a single sink pin - but the above statement makes it look like this wouldn't work.

The question is will this work or not?

The LEDs have a forward voltage of 2V and max current of 20mA. I was planning to use a 100Ω resistor in series with each LED which means current should be limited to 13mA per LED.

I would like to build the project as described as it will save on wiring (I have buttons, potentiometers and encoders to wire up!) - though I think I have plenty of digital pins free still to have one pin per LED and by sinking to ground.

It is always best to show us a schematic what you are proposing.

If 8 LEDs are ON each at 20ma, what current will flow through the sinking pin :wink:
.

LarryD:
It is always best to show us a schematic what you are proposing.

If 8 LEDs are ON each at 20ma, what current will flow through the sinking pin :wink:
.

I am pretty sure TOO much but I would like to be wrong haha

Here's the project so far, slightly lacking in the wirey chaos that is to follow:

D10 and D11 should be limited to ~20ma, you would be trying to push 160ma.

You will need to add transistors to take that much current.

A logic level MOS FET would be best but a BJT should work also.

.

LarryD:
D10 and D11 should be limited to ~20ma, you would be trying to push 160ma.

You will need to add transistors to take that much current.

A logic level MOS FET would be best but a BJT should work also.

.

A yes, good idea! So D10 and D11 controlling the base of an NPN to tap a flow of current - that should work great thanks!

Something like Q5 then change R14 to 220R.
A 2N2222A should work.

.

Great, yep that's what I had in mind, thanks a lot!

I should have no trouble getting them on that bit of veroboard as well :slight_smile:

With 100 ohms for each LED you could be drawing ~240ma from the Arduino.
i.e. 30ma per o/p. should reduce this to 20ma.
If the regulator gets hot, keep the wallwart down to 7 volts or make the resistors larger, something like 220R or larger.

.

Not sure what else you have going on, but the due has a max of 130mA combined from ALL I/O pins. Maybe play around and increase the resistors to achieve an acceptable brightness and drop the current down some more.

Hey folks he is talking about a Due here, direct driving of an LED should be limited to less than 15 mA on the big pins and 3mA on the little ones. Don't ignore that. I would say it makes the project untenable as currently envisaged.

Thanks for the replies all, ok I missed the max current stat as well. Other stuff going on is sampling pots (voltage from the onboard regulator not the micro) some buttons and encoders and a pair of RGB leds - oh yes and a MIDI out which again will be buffered from the regulator. Each LED in the sequence will be driven with 13mA by my calculation - I could double the size of the resistor so they only draw around 7mA each, I wonder if they would be bright enough then though, I could maybe test that now on breadboard. And then I would have to take my jig apart gaaaah! :stuck_out_tongue:

If they are transistor driven though then the current will come from the on board regulator, not the micro and the page says that has capacity up to 800mA - I shouldn't get anywhere near that

Ah wait no, I'm not thinking about this properly, the LED transistors won't be sourcing from the regulator, they will be sourcing from the anode pins, the idea there was to address the sink current issue - hmm looks like I will have to increase the resistors or look for a different solution.

Paul__B sent me a private message on this issue and mentioned the MAX7219 LED matrix driver IC might be a good idea - I don't have time to get those before I go away next week, but I do have some nice shift registers which I guess could be the next solution

If they are transistor driven though then the current will come from the on board regulator, not the micro

Yes correct.

I could double the size of the resistor so they only draw around 7mA each,

Yes but even that would be too much for the small capacity pins.
Do you know what pins can source 15mA and what can only source 3mA?

the LED transistors won't be sourcing from the regulator, they will be sourcing from the anode pins,

No you can't source from an anode, an anode is connected to positive, sourcing from that makes no sense.

Grumpy_Mike:
Yes but even that would be too much for the small capacity pins.
Do you know what pins can source 15mA and what can only source 3mA?

I'm not sure on this actually - will have a look now.

Grumpy_Mike:
No you can't source from an anode, an anode is connected to positive, sourcing from that makes no sense.

I thought you say "source" from a more positive point and "sink" to a more negative?

Just tested a 220r resitor and my yellow 3mm LEDs are still plenty bright. I am leaning towards using a shift register now though...

I thought you say "source" from a more positive point and "sink" to a more negative?

No source means where the current comes from. You source current from a pin and light an LED by connecting it and its resistor ( in series ) from the pin to the ground. To turn on the LED you set the pin high.

Sink means the current goes into the pin, the LED and resistor are connected to a high voltage, say 5V, and the current flows into the pin. To light up the LED you put the pin to low.

Ok, my understanding is right but my description is wrong. Thanks for clearing it up Grumpy_Mike.

I had a play around on breadboard this afternoon and got things working nicely with two npn transistors. I used 470Ω resistors in series with the LEDs in the end, so current should be limited to about 2mA per LED now, there is plenty of brightness in the LED. To be extra sure anyway (and it is necessary to have different things going on on each row), I cycle between the two transistors, I can do this at a rate that flicker isn't too apparent. But cycling too fast starts generating odd behaviour where switching at some point is too slow (the transistors presumably). Anyway, it works a treat for now :slight_smile: Will be interesting to see how it holds up in a more complex real time sketch.

where switching at some point is too slow (the transistors presumably)

No switching will not be too slow. What ever is going on it is not that.