Basic transistor Buffer to control lots of LEDs

Hi all. I'm a high-school student with what is probably a really simple question. But I need an answer ASAP for a competition project and we're on holidays so I can't contact my teacher.

I'm using an Arduino Duemallinove (ATmega 328) to turn a large amount of standard LEDs wired in parallel to a single Digital pin on the Arduino.

There would be in excess of 20 LEDs on a single pin. The LEDs are simply wired in parallel, they are not in a matrix or 7 seg display. And when the project is complete around 10 of the digital pins will be in use.

My teacher briefly told me I will almost certainly be drawing too much power from the Arduino (he has no experience with them). He suggested I use a single transistor buffer on each pin to control the current flow.

Problem is I have very little experience with buffers or the limits before you overload the Arduino. Can someone please tell me how many LEDs can be safely connected to an Arduino without a buffer, and if I were to use a buffer, what values for the resistor and transistor should I use.

Oh and to make matters more confusing, a friend of mine building a similar project went ahead and built his circuit without a buffer. The LEDs worked perfectly and his Arduino was fine. Still I want to be safe rather than sorry.

You can safely draw about 20mA out of an Arduino pin. That will run between one and two LEDs in parallel (assuming 10-20mA per LED. You'll still need the current limiting resistor.)

If you want to have more than 2 LEDs in parallel, you can either run them at lower currents (3-4mA is often bright enough for indicator lights), or use a transistor to switch them. Another alternative is putting LEDs in series - at 5v, you can usually put 2 LEDs in series, and two sets of two makes four LEDs per pin at 20mA total (10mA per LED).

Of course, since you say there will be >20 LEDs per pin, you SHOULD be using a transistor to switch them. The simplest way to do this would be to get a logic-level MOSFET, and hook it up as a switch for the LEDs. here's a quick tutorial I just googled. Using a bipolar transistor is of course possible as well, but it tends to require more understanding of the transistor and its associated calculations than you appear to have... you can probably learn if you wanted to, though.

As for your friend, you can draw up to ~40mA out of a single pin, it's just a relatively risky thing to do (you may burn out the pin). Two sets of 10 LEDs in series with 4mA per LED would just about hit that limit, so it's theoretically POSSIBLE (just not very smart).

Thanks for the replies.

The LEDs are simply being powered by the ~5V Logic HIGH level from the arduino board. I don't have access to the exact specs, but we've been testing with a standard voltage drop of 2V and a current of 20mA with no trouble.

KE7GKP, the circuit you provided was very similar to the one my teacher described, except more like this

I understand enough about transistors to understand how that would work. I just don't know which transistor to use, and what resistance to connect between the base and the pin.

I would rather do this than use a MOFSET, as transistors are more readily available to me. But if you believe this is the only option I would consider it.

What transistors do you have available to you (datasheet links are good).

With a voltage drop of 2v, you could easily put 2 LEDs in series, and not only save on resistors, but waste less power! (49 ohm resistor instead of a 100ohm resistor). Although, going by your schematic, you're actually driving the LEDs at 30 mA... It should be a 150 ohm resistor for one LED at 20mA w/ 2v voltage drop.

There's a transistor calculator here, plug in the values from your transistor's datasheet and it should give you appropriate resistor values.

Ignore the resistor values for the circuit I provided. They are wrong, I will have to double check later as I cannot remember of the top of my head.

I want to run 20mA through the LEDs with a voltage drop of 2V.

I have access to most types of NPN and PNP transistors through the school. I couldn’t give you specifications sorry. That’s what I need.

For the purpose of this project for the moment it is best to have 1 Resistor per LED, in future redesigns I’ll keep in mind I can run 2 LEDs in series.

The Arduino is powered by a 9V power supply. It is possible that I could use that as part of the supply for the LED, but I still need to be able to control the logic levels. How would this be done?

I guess the situation is I have the circuit built in a set way with a set resistor value, which is running at the appropriate levels throughout the circuit. I just need to pick a transistor for that circuit to protect the Arduino.

Um. Either a 9V battery or 6 AA Batteries in a clip to make an ~9V supply. I've never had any trouble using these with LED and motor loads before.

So basically calculate the total current load for that pin and then I should be able to work out which transistor to use?

Obviously.

I may not be super advanced in electronics, but that’s given. FOR that pin, not actually connected to the pin. Considering I may be using multiple pins.

Bad wording on my part.

You can get a bit hung up on datasheets and whathaveyou. For something as simple as this, driving a few mA into a TIP120 with the LEDs as common-cathode loads (i.e. all the anodes to the positive rail, suitably-buffered) will usually be fine. A TIP120 will saturate virtually completely with 4mA base current and a 2A collector current, well within your per-pin current limit. 2mA is a good starting point. 5V @ 2mA ~ 2500R, call it 2K7. Probably 3K3 or even 3K9 will work just fine. Substitute it for 1K8 or 1K5 per your collector current. Use a pot. Put an ammeter in the base, and the collector, and keep an eye on them. You will learn things!

Your LEDs will be taking 10mA max forward current if they're miniature display types. LEDs are diodes, so small deviations in forward voltage translate into big differences in drawn current. Multiple LEDs are typically connected in series, so there's a roughly 1.8V drop per LED. With a 9V supply, and a Darlington type transistor like the TIP120, that means realistically 4 LEDs per string, and five strings in parallel if you want 20 LEDs. Brightness per string could probably be managed with a small series resistor and a pot per string. You probably don't want to get into constant-current drivers.

A TIP120 can easily handle a couple of watts, so you're fine (maybe heat sink it if you're nervous, but with the base resistor even if it goes crazy and crowbars the Arduino pin to ground you'll still only be pulling 2-4mA max.) It's often not a bad idea to put a small resistor, e.g. 22R or 47R between the emitter and ground to pull down the collector load and make sure it's fully off when the logic on the base pin is low (this increases switching speed, but it has the whole collector-emitter current through it in the on state, so check power rating. A 1W metal film type will be ample.) A TIP120 is a Darlington-type, so remember you get twice the BE drop of a normal NPN BJT. The numbers here are very conservative, so don't sweat it.

This is just a transistor switch, i.e. all your LEDs on or all of them off. To do anything more sophisticated needs a lot more effort. If you want a bargraph, there are ICs to do that. The only crucial thing to remember here is: if you are doing this YOU WILL NEED AN EXTERNAL POWER SUPPLY. You cannot run this off a simple Arduino running through a USB connection. There is a very good reason an Arduino has an external power jack. A 9V 1A wall-wart supply is $5-6, a lot less than a fried Arduino, and a LOT less than a fried USB port on your host computer. You are operating at around the limits of breadboards, as well. I've seen those things melted because people forgot that 'plastic chunk with tinfoil connectors' != 'PCB with 5A traces on 2oz FR4'.

I recommend typing 'TIP120 datasheet' into Google and having a look. TIP120s are cheap (80 cents each, 35 if you buy 'em like you mean it.) They're my go-to power BJT for prototyping. 2N3904s are great for small signal stuff. 2N3055s if you want 15A. They're oldies but they're goodies.

I understand enough about transistors to understand how that would work. I just don't know which transistor to use, and what resistance to connect between the base and the pin.

I use 1 k to 4.7 K. Ardiuno - resistor - base of transistor. The transistor 2N3904 - max current 200 mA. TIP 31 - max current 5 A. Check the data sheets for max Ic. to make sure.

LED current of 10 ma is a bit to much. I use a 330 ohm-470 ohm to a LED with 5 V supply. A 9 V, I use 680 ohm. Just to be on the safe side.