The normal accepted hobbiest way of driving a small LED is to drive it directly from a logic IC pin. I've heard over and over that this is not the right way to do it and I can understand why. The Arduino has a reasonably low maximum drive current for the whole package and a lot of TTL packages have poor drive current. But lighting LEDs this way is still done. Now, what is the right way? Say that I have a pin and want to light a 20mA LED on logical 1 and draw 1mA of current from the pin. The obvious way (to me) is to connect the LED through an NPN transistor, right? Connect the output pin through a 5K resistor to the base of the transistor (1mA current), connect +5V to the LED, through a 250 ohm resistor (20mA to the LED) to the transistor collector, connect transistor emitter to ground. Does that sound right? If so, what is a good transistor choice? How do I know that 1mA on the base will give me at least 20mA from the emitter to the collector. How do I know the transistor is open and not operating in the ohmic region? Thank you. I am not too familiar with discrete transistors.

I've heard over and over that this is not the right way to do it and I can understand why.

I can't. There is nothing wrong with driving an LED and its resistor directly from a processor pin. It is done all the time. As long as the current capacity of the pin is up to the job.

Quote

The Arduino has a reasonably low maximum drive current

No, in comparison with other processors it is very high.

Quote

a lot of TTL packages have poor drive current.

Source rating yes but they are much better at sinking.

Quote

The obvious way (to me) is to connect the LED through an NPN transistor, right? Connect the output pin through a 5K resistor to the base of the transistor (1mA current), connect +5V to the LED, through a 250 ohm resistor (20mA to the LED) to the transistor collector, connect transistor emitter to ground. Does that sound right?

Yes. Although you won't find many 5K resistors use 4K7.

Quote

If so, what is a good transistor choice?

The cheapest transistor you can get. Sights like Farnell allow you to sort them by price.

Quote

How do I know that 1mA on the base will give me at least 20mA from the emitter to the collector.

You look at the data sheet and see that the gain of the transistor you are using is at least 20.

Quote

I am not too familiar with discrete transistors.

Yes I know that from this:-

Quote

How do I know the transistor is open and not operating in the ohmic region?

No such region, do you mean saturated? It is down to the gain of the transistor.

I know the ATMega328P is a pretty good driver compared to most microprocessors, but it is not a driver. The maximum package source current is 200mA. That is all I was getting at. In this case, really I want to drive LEDs (correctly)from a TTL package. Since I want to turn on an LED for logic 1, the fact that TTL has good sinking current is not meaningful as far as I can see, but maybe I am having tunnel vision here in some way.

It's far too much trouble to wire up an NPN inverter for every single Led. Also, newer Leds don't need anywhere near 20 mA to get good output, more like 4-5 mA on many. If you'reworried about current drive off the I/O pins, just buy some high-output Leds.

Quote

I've heard over and over that this is not the right way to do it and I can understand why.

Duh. The only thing right about *the right way* is don't exceed the current source/sink rating for the I/O pins.

Can someone recommend a good NPN transistor for my scenario? 1mA to the base must allow 20mA from emitter to collector while saturating the transistor. Correctly stated?

A couple of popular low(ish) current npn transistors:

2N39042N2222A

For driving simple 20ma leds I like the 2N7000 mosfet transistors, no series base (gate) resistor needed and they are cheap.

Lefty

OK, I know I have all of these in my Jameco transistor kit. 100 of the 2N3904s, and only 10 each of the other two. I will try that out. I especially like the MOSFET idea, thank you.

Edit: The 2N7000 looks like a great part and Jameco has free shipping this week on orders of $25 or more so I picked up five hundred of them, five cents each (and some anti-static foam which normally really kills me on the shipping cost). I guess I am set for life.

I should also note, for my silly current project I am actually working with 74LS TTL packages again and I want LEDs (on 330 ohm resistors) on some of the inputs and outputs. An issue I have is that the input LEDs are obviously dimmer than the inputs so clearly the package can't supply 15.15mA and probably I am pulling it at max which can't be good, hence I think I need the transistors. I like the idea of using these MOSFETs, it's a part I have not used so far.

I know the ATMega328P is a pretty good driver compared to most microprocessors, but it is not a driver. The maximum package source current is 200mA.

Well...aiming at exactly 20mA with just a resistor is a bad idea. Much better to aim at the 12-15mA mark.

In that case 200mA is 13-16 LEDs. About as many as you can physically connect to an Arduino.

(Of course this requires the user understands the limitations, which isn't guaranteed ... remember the guy who connected 60 LEDs to a single Arduino pin then posted about them being a bit dimmer than he would have liked?)

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

200mA. That is all I was getting at. In this case, really I want to drive LEDs (correctly)from a TTL package. Since I want to turn on an LED for logic 1, the fact that TTL has good sinking current is not meaningful as far as I can see, but maybe I am having tunnel vision here in some way.

Yes you are totally missing the point. Why the fixation with a logic one turning it on. Anyway if you use an open colllector buffer and power the LED by sinking a logic one will turn it on. Try an 74LS05.

Quote

How do I know if I saturated the transistor to keep the emitter to collector resistance minimal

Back to front. When the collector emitter voltage is at a minimum you have saturated the transistor. You saturate a transistor by having more current through the base than the collector current divided by the gain.