Transistor as a switch. Having a hard time with the equasions/ data sheet

It seems the more I read about transistors the more confused I get. I think the most frustrating thing is how the datasheets can be a little overwhelming.

I figure I’ll explain what I’m trying to do and what I think I need to make it work, and if you guys can assist me on going the right path, I’d really appreciate it.

I have a couple RGB led strips that I want to connect to 3 pins of the arduino. Below is the current draw for just one led bar:

  • Red: 100mA @ 12v
  • Green: 80mA @ 12v
  • Blue: 87mA @ 12v

So now I need 3 transistors. I start by finding Vload and Iload(max). The Vload on the led bars is 12v and for the Iload(max) I doubled red’s current draw for the two bars and added 100mA for safety. I got Iload(max) = 300mA.

I chose the PN2222 NPN transistor(datasheet) because the Ic(max) of 1A and the Vceo of 40V seems perfect and so far I think I’m on the right track.

The next step is to calculate the base current needed for saturation. On figure two of the datasheet I find ß=10 and assume this means that for an Ic of 300mA or lower I need a base current of Ic/Ib = 10 or Ib = 30mA.

At this point I think I’m doing alright. Then comes the choosing of the base resistor and I become unsure of myself.

One source says to look at Vbe(sat) which is in figure three of the datasheet. I see 3 lines, and I choose the line marked 25°. I try to guess where 300mA would be on the chart and it looks like it’s above 0.9V but below 1.0V, so I (probably incorrectly) assume 0.9V and do the equasion:
Arduino is outputting 5V, so the resistor has a voltage drop of (5V - 0.9) or 4.1V across it. Ohm’s law gives me V/I = 4.1/(30mA) = 136 Ohms. I should choose a 150 Ohm base resistor.

The other source I found says to use this equasion: V/Ib with a 0.7v drop across the base junction. So, V/Ib = (5V-0.75V)/30mA = 141 Ohm. I should choose a 150 Ohm resistor.

Did I do this right? Should I have done something different?

That's pretty much spot on for the transistor I think - however you need to realize that when outputing 30mA the Arduino pin will be struggling and will be below 5V (see the ATmega328 datasheet). Its close to the limit for a single pin too (40mA).

So the easiest thing will be to try a 150ohm and measure what actually happens with your transistor (current gain specs are worst-case and there's usually a big spread (factor of 2 or more) in actual device gains.

Also the 2N2222 is a very old transistor, there are modern devices with much better gains at high current if you look around (I use the STX724 for switching, 3A 0.9W and gain of 80 at 1A (Vsat 0.4V at 1A).

This is a great example of where a simple constant current generator comes into it's own, a transistor, led, and two resistors. See my scribbled sketch :- ( I still haven't mastered the inserting pics here ! )

http://www.flickr.com/photos/johnandlyn/5506763085/

The bottom part is the actual circuit, the top part shows the calculations, the only critical component is the emitter resistor, which sets the current through the LEDs , and can be trimmed to suit.

The advantage of this circuit is that the current through the LEDs will be almost the same as through the emitter resistor ( minus the tiny base/emitter current )

As long as the LED on the base is lit, it will have 2.1v on the base for a red LED, so the emitter will always have 0.7v less due to the base emitter forward bias, = 1.4 volts ( in our example with a 2v1 LED and a 0v7 base emitter bias voltage )

This means that the transistor will always try to draw enough current through the LEDs in the collector circuit to maintain that emitter voltage, so if you pick the value of the emitter resistor to drop this voltage ( by Ohms Law ) for whatever collector current you require, it doesn't matter how many LEDs there are in circuit, or what the supply voltage is, you will get the same chosen current through every LED. ( as long as there is enough supply voltage, and the transistor can handle the heat if the voltage is much higher than required )

I have scribbled some first choice resistor values for the three LED strip currents that you mention, but start with a 22 ohm say, and using a meter, put resistors across it in parallel until you get the current you want.

Using a red LED for the base reference voltage, rather than 2 diodes in series, is that the voltage/temperature drift of the LED cancels out the transistors drift - ( I read somewhere back in the sixties, and it seems to work.)

Thanks for the fast reply MarkT. I really appreciate the time you took to respond. I was a little confused by somethings you said and was hoping you could clarify.

however you need to realize that when outputing 30mA the Arduino pin will be struggling and will be below 5V (see the ATmega328 datasheet). Its close to the limit for a single pin too (40mA).

I understood the limit was 40mA per pin and I was under the impression if I stayed under that everything would be fine. I didn't know that the pin would be under 5V, though. So what do you do for calculations? What milliamp range do you try to limit the arduino pin to? What voltage will the arduino will be outputting? Does this voltage change somehow or is it static?

So the easiest thing will be to try a 150ohm and measure what actually happens with your transistor (current gain specs are worst-case and there's usually a big spread (factor of 2 or more) in actual device gains.

I think I get what you're saying. I could be getting more of a gain than I assumed but does that somehow lower the current draw on the arduino pin?

Also the 2N2222 is a very old transistor, there are modern devices with much better gains at high current if you look around (I use the STX724 for switching, 3A 0.9W and gain of 80 at 1A (Vsat 0.4V at 1A).

This is good to know. I think the biggest problem I'm having is with this concept of gain (power dissipation too, but I'll tackle that later). When I was calculating the base current needed for saturation was the ß=10 the gain? So, if I had a gain of 80 it would then be ß=80 ?

I understood the limit was 40mA per pin and I was under the impression if I stayed under that everything would be fine

No 40mA is the point where you start doing damage not the point where it works well. Stick to 20 to 30mA.

Does this voltage change somehow

Yes the more current is drawn out of a pin the lower the output voltage is. This is because of what is known as "source impedance".

I could be getting more of a gain than I assumed but does that somehow lower the current draw on the arduino pin?

No the limit on the arduino current is simply the base resistor. If you get more base current than you need you don't get any thing happening except a slower turn off time for the transistor because of charge storage.

the ß=10 the gain?

Yes

So, if I had a gain of 80 it would then be ß=80 ?

Yes

I <3 you mike.

How about pull-up/pull-down resistors with transistor switches and the Arduino? Is this something that isn’t necessary, always necessary, or conditional?

eco:
I <3 you mike.

How about pull-up/pull-down resistors with transistor switches and the Arduino? Is this something that isn’t necessary, always necessary, or conditional?

In the arduino context, pull-ups and pull-downs are assosicated only with Arduino digital input pins and even then only if required by the type of component wired to the input pin.

An Arduino digital output pin is both a active source and sink of current, so pull-ups are not required. The only time a pull-up is required for an output pin is when it’s an open collector or open drain type output, which doesn’t apply to Arduino pins.

Lefty

On figure two of the datasheet I find ß=10 and assume this means that for an Ic of 300mA or lower I need a base current of Ic/Ib = 10 or Ib = 30mA.

That seems unreasonably high. Elsewhere beta is claimed to be at least 40, even for 500mA collector current, so while your 30mA figure would certainly deeply saturate the transistor, I suspect that it would operate just fine with half that current (which would be much easier on the AVR…)

Update
I ended up choosing this transistor: http://www.mouser.com/ProductDetail/Fairchild-Semiconductor/KSD471ACYBU/?qs=UMEuL5FsraCzUpcrkp2odg%3D%3D

It seems to work well except that my transistor stays in a partially on stage when the arduino pin is LOW, keeping the red color on but very dim.
Is there a remedy for this?

Below are the values I’m using.
Vbe(sat): 1.2V
Ib: 2.67mA
Ic: 267mA @ 12v
Base Resistor R=VI = 1.2V/(2.67mA) = 449 or a 470 ohm Resistor.