Driving many LED from Arduino Mega via transistors (UDN2981), no multiplexing

Hi,

I'm working on a model of a crossing with traffic lights. The crossing is rather large, having 129 LEDs distributed in 15 traffic light posts, with their cathodes bundled together. For example, a post with 9 LEDs has 10 micro-cables going out - nine for each LEDs anode and one for all LEDs cathodes.

In order to control the traffic lights, I got an Arduino Mega 2560. I'm trying to avoid multiplexing since the programming and wiring of the whole thing is already quite complex, and I'm an electronics noob having a hard time understanding all of it. So the idea is to wire the LEDs anodes directly to the Arduino Mega 2560 with its >60 pin-outs. Not all the LEDs need to be controlled individually - most of the time two or three LEDs will always light up together - so I can easily wire them in parallel to the Arduino's output pins, of which 57 will suffice.

Well, in this Forum I've read about the maximum current allowed to be drawn out of each Arduino pin to be 40mA, and the maximum overall current to be about 800mA. [1] This won't work with each LED drawing 20mA. Even if there is never a time when all LEDs are lighting up at the same time, the current for 50 LEDs would be too much already.

As a solution, I tried using a Darlington Array of transistors driven by the Arduino. Since the LEDs are bundled in their cathodes, I would need a high-side drive array, and went for the UDN2981a and (since it is discontinued and I had only 3 pieces available) the Toshiba TD62783. This is the plan for one of these pieces (there are 7 of them in total):

scheme.png
[see image attachment 1]

To be more precise, the Arduino is powered either (a) via the same +9V power source as the LED via its 5.5mm power jack, or (b) via its USB interface (when programming), or (c) both.

I started wiring the LEDs and it worked as designed, I was happy. However, when I removed the 9V power input for the LEDs and the Arduino, and just used the USB interface as a power source for the Arduino, the LEDs are still lighting up (just not as bright as with 9V). From what I understand, this is due to the Arduino still supplying them with 5V via the transistor array's base pins. But also, from what I understand, the base pins should only allow a minimum current that shouldn’t light up the LEDs.

I tried to get my head around how that UDN2981a thing works in detail and looked into the schema for each of its 8 drivers [2], but all I got was a headache. :wink: Still, from what I understand, there should be no reason for INPUT current to flow through OUTPUT if GROUND is connected correctly:

one of eight drivers.png
[see image attachment 2, taken from [2]]

So my question is, in the above schema, is it okay for the LEDs to light up? And can they draw 20mA from the Arduino’s output pins through the transistor’s base inputs? Should I worry about supplying the Arduino with power via USB without the 9V? Or should I worry about the overall solution?

I looked up this issue using Google and the forum search, but every solution I found so far uses multiplexing [3] or points towards ULN2803A or UDN2981a and that it should work. Again, I would like to avoid multiplexing and more complex programming / wiring solutions. And I am rather new to this, so please bear with me. Also, I’m sorry for that block of text, but I hope to have described everything elaborate enough. :sweat_smile:

[1] Maximum Current Draw from Arduino Mega - Project Guidance - Arduino Forum
[2] UDN2982A pdf, UDN2982A Description, UDN2982A Datasheet, UDN2982A view ::: ALLDATASHEET :::
[3] How many 20mA LEDs can I hook up to Mega 2560 - LEDs and Multiplexing - Arduino Forum

scheme.png

one of eight drivers.png

You could also use MIC2981, it is an actively produced part. Digikey shows they have 941 in stock.

Input current needed is small, < 1mA, while output current can be large, up to 350mA.

(Watch out for the forum sticking extra characters to the beginning and ending of that)

129 LEDs distributed in 15 traffic light posts, with their cathodes bundled together.

You really should have come for advice earlier. The direction you've taken with the design is going to be a nightmare, what with all those wires.

Do you have any possibility to re-wire the LEDs? Common cathodes is much harder to deal with than common anodes.

How bright are those LEDs at 20mA? Modern LEDs can be dazzling at that much current, and often as little as a few mA can be enough for most purposes. This would solve a lot of your problems.

Yes, common anodes would've been easier, I also came to that understanding :wink:

Wiring was done a few years ago when I was under the impression that driving them directly via the Arduino's output pins would be possible. That this wouldn't work was something I realised while the project rested, while working on other stuff. Unfortunately, the wiring within the traffic light posts cannot be changed without a lot of effort. And I mean a real lot. :confused:

Ok. But what about the led series resistors. Can they be changed/removed? What value(s) are you using now, and what are the forward voltages of the LEDs (red/yellow/green)? How happy are you with the current level of brightness?

What else about your project is now fixed and cannot be changed? For example could you replace that 9V PSU with a much more suitable 5V one?

Changing the voltage from 9V to 5V would need a resistor change as well to keep the current the same. Are the resistors in the wiring in the poles with the LEDs?
You can buy more of the same current source driver, the part number is just slightly different as I noted.

PaulRB:
Common cathodes is much harder to deal with than common anodes.

That's interesting; I tend to wire things as CC but have no reason for doing so other than habit.

Can you elaborate please?

PaulRB:
Ok. But what about the led series resistors. Can they be changed/removed? What value(s) are you using now, and what are the forward voltages of the LEDs (red/yellow/green)? How happy are you with the current level of brightness?

What else about your project is now fixed and cannot be changed? For example could you replace that 9V PSU with a much more suitable 5V one?

Okay here's some data:

  • red LEDs: 1.9V
  • yellow LEDs: 1,9V
  • green LEDs: 3.2V
  • white LED: 2.9V
  • Resistors = 470 ohm (same for all)

The green & white LEDs are very well bright enough, the others are okay but shouldn't be much darker. They are shining through a foil - since it's a model railway layout the whole thing is tiny. :wink:

The resistors can be changed easily.
The 9V supply can also be changed, but from what I understood using 5V to power the Arduino via it's Vin pin cannot be used together with its USB interface - that concerns me.


Do you have an idea about my above question - why is the arduino lighting up the LED via the UDN2981a's base pin? I thought the point of this piece is to reduce current and voltage needed to drive its outputs. :neutral_face:

You have a lot more options for individually sinking current than sourcing current.
Options like TPIC6B595 or TPIC6C595, which combine shift register and high current sink outputs (150mA and 100mA respectively). Then send data into a bank of shift registers and only use 3 IO pins (I use SPI myself, so just a latch signal, a data signal, and a clock signal). I have sent as much as 45 bytes out at a time at 8 MHz rate, achieving a 20KHz refresh rate.
I know of no high current source output shift registers that one could use to do the same, hence you'd have to use both 74HC595 and MIC2981 to achieve the same (or a lot of Mega outputs buffered with MIC2981).

Another option would have been to use 2 MAX7219 to drive 128 LEDs, and a Mega output to drive a lone 129th.
MAX7219 multiplexes the LEDs in groups of 8 and controls current itself, so all the resistors would not have been needed.

I don't follow your concern on the '2981. The input pin turns on the high current output driver. The input only needs <1mA. If the input is high, the lower left transistors conduct to turn on the upper right transistors and provide the output current.

If Vin/2 is > 3.3V (i.e. 6.6V), than Vin is selected for the power source if USB is also connected.
Vin must be greater than 5V for the 5V regulator to work.
The barrel jack needs to see ~ 7.5V, it is followed by a reverse polarity diode that drops another ~0.7V, so Vin at the power header becomes ~6.8V, sufficient for the regulator and to also select the regulator output for the 5V supply vs the USB supply. USB has a limit of 500mA, protected by the resettable fuse near the USB connector (the flat greenish/gold device). The barrel jack/diode can support 1000mA, the regulator 800mA if the Vin-5V difference is not large (7.5V) altho the regulator may still overheat and turn its output off and on as it cools down, then overheats, then cools down ...

The red and yellow LEDs will have around 15mA flowing through them. The white around 13mA and green around 12mA. If you switch to a 5V supply, you will need lower value series resistors, 150R for green and white, 220R for red and yellow, although they might need to be adjusted to compensate for the voltage drop of the driver chips, which with UDN chips, can be significant.

why is the arduino lighting up the LED via the UDN2981a's base pin?

I have a theory, but no proof. Look at the "One of Eight Drivers" diagram. You see that diode joined with dotted lines between ground and input? Its called a "clamping diode" designed to protect the chip from damage by static in transit/storage. There might be another one, not shown, between the input and Vs. if I'm right, that could be how a significant current from the input can reach the output if the 9V supply is not connected. These clamping diodes are not designed to carry large currents for long periods, and could be damaged, causing damage to the whole chip. So what you may be seeing is what's called "parasitic powering" where a chip, and devices connected to it, are powered via the chip's inputs rather than it's power pin.

Yes, resistor values need to take typical Vce of 1.7V at low currents into account.
So, (Vs - Vce - Vf)/.015A = R
With 5V, 1.7V, and 2.2V say for a Red LED, then:
(5 - 1.7 - 2.2)/.015 = 73 ohm, so a standard value 75 ohm would work well.

Vce might be lower with lower currents.
5V might be lower when powered from USB as there is voltage drop across the resettable poly fuse that can vary with current (V = IR, if R is constant, and I increases, then V increases).

hannah_mackinlay:
I tend to wire things as CC but have no reason for doing so other than habit.

Common anode is easier because there is a much wider choice of driver chips which switch on the low side (cathode side), especially if higher currents or constant-current drive is required. High-side drivers often have to be constructed from individual components (pnp bjt or p-channel fet). So if you need to control many channels, is easier to do that on the cathode side rather than anode side, so common anode is the way to go.