# Arduino Forum

## Using Arduino => General Electronics => Topic started by: charis on Feb 09, 2013, 10:52 am

Title: A couple of questions on the 2N2222 transistor
Post by: charis on Feb 09, 2013, 10:52 am
Hi, this is my first post!

I recently started in the world of electronics and i am trying to make myself comfortable with various parts before starting to build real projects.

If this image is taken as a basis, i am struggling to calculate the correct values for R1 and R2:

(http://www.sqlskills.com/blogs/paulselec/image.axd?picture=2010%2f1%2fSimpleTransistor.jpg)

As with the image, the voltage across the collector is 5V and the current through the Led should be 20mA. The datasheet states that the Collector-Emitter saturation voltage is 0.3V when the current at the collector is 150mA and 1V for a current of 500mA so i assume that for 20mA is even less than 0.3V?

Then if i understand right R1 = (5-0.3)/0.02 = 235 Ohm ?

For the base i am completely lost. The datasheet states that the Base-Emitter saturation voltage is 1.2V when the current at the collector is 150mA but what about a current of 20mA at the collector? Furthermore, the DC Current Gain is 75 for Vce = 10V, Ic = 10mA and 100 for Vce = 10V, Ic = 150mA, but i have a Vce of 5V and a Ic of 20mA. What is the correct gain so that i can calculate the correct value of R2?

Thank you!
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Krodal on Feb 09, 2013, 12:28 pm
Try to find a good datasheet, with lots of data. Some datasheets are very short.

The voltage drop over the transistor is perhaps only 0.1 or 0.2 V at 20mA.
But the led has a voltage drop of 1.4 ... 3V. That depends on the color. http://en.wikipedia.org/wiki/Light-emitting_diode#Colors_and_materials

If you want the transistor to be fully on, use about 30% more current through the base than needed.

Suppose the led has a voltage drop of 2V. 3V/20mA = 150 Ohm.
The current gain with Ic at 20mA is about 70. 20mA / 70 = 0.29mA. Add 30% makes 0.37mA.

For safety I assume that the output of the Arduino is 4.5V and the base about 0.7V. 4.5-0.7 = 3.8V
3.8V / 0.37mA = 10k

So 10k would do the job, and 4k7 doubles the base current to be sure. It doesn't hurt the 2N2222.

Title: Re: A couple of questions on the 2N2222 transistor
Post by: fungus on Feb 09, 2013, 12:34 pm
The main point of the base resistor is to stop too much current coming out of the Arduino and hurting it.

As such, there's no 'correct' value, anything which lets less than 40mA out of the Arduino pin and more than what the transistor needs to full open will do.

OTOH, 40mA isn't a good design goal for an Arduino pin. You should be able to open the transistor with far less than that.

This page helped me a lot when I started out with transistors: http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt_theory.html

Title: Re: A couple of questions on the 2N2222 transistor
Post by: JimboZA on Feb 09, 2013, 12:45 pm
Quote
This page helped me a lot when I started out with transistors: http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt_theory.html

Ok, I'm about halfway down the first page of that link and already things are making sense. Things that I first tried to understand about transistors when I was 13 in 1969.

That link ought to be Transistors 101 for everyone.

"I have a question about transistors...."
"Wait, have you read Transistors 101 (http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt_theory.html)?"
"No, but...."
"Uhuh.... no "buts".... read it then ask if you still need to"

Title: Re: A couple of questions on the 2N2222 transistor
Post by: cjdelphi on Feb 09, 2013, 12:48 pm
I generally use a 1k on the base, and around 200 - 250ohms from a 5v supply to power a small 5mm LED.

5/1000

0.005 amps at the base of the transistor (it can handle up to 40ma (0.040amps)

Title: Re: A couple of questions on the 2N2222 transistor
Post by: charis on Feb 09, 2013, 04:57 pm
Thank you all! Just for reference, i eventually used 10kOhm in the base and 100 ohm as a current limiting resistor, for ~100 ?? base current and ~11 mA through the LED :

(http://i45.tinypic.com/rivh4y.jpg)

https://www.circuitlab.com/circuit/gmmqaq/2n2222-led/ (https://www.circuitlab.com/circuit/gmmqaq/2n2222-led/)
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 07:21 pm
I'm curious why OP chose to switch the high side instead of using the original circuit. With this setup, the transistor is operating in the linear region and will never reach saturation.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: CrossRoads on Feb 09, 2013, 07:56 pm
Yeah, but with that freaking fritzing program you can't tell that - have to go look up the parts and see which pins are B, E, C - which was totally obviouse in the original post.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 08:00 pm

Yeah, but with that freaking fritzing program you can't tell that - have to go look up the parts and see which pins are B, E, C - which was totally obviouse in the original post.

The link goes to a CircuitLab (https://www.circuitlab.com/circuit/gmmqaq/2n2222-led/) page that makes it easier to evaluate.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: retrolefty on Feb 09, 2013, 08:01 pm

Yeah, but with that freaking fritzing program you can't tell that - have to go look up the parts and see which pins are B, E, C - which was totally obviouse in the original post.

Hey Bob, why are you not out shoveling snow off your drive way.  ;)
Title: Re: A couple of questions on the 2N2222 transistor
Post by: CrossRoads on Feb 09, 2013, 08:15 pm
This is from an upstairs window - can't really tell, but the undrifted snow is 20" deep, and the pile from the city plows at the end of the drive is 4 feet and 8-10' wide.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: charis on Feb 09, 2013, 09:54 pm
Ok, now i am a little lost. Remember, i am new to electronics...

Quote
The way to deal with this is to calculate the
"nominal" base current required for the app, and then about double it, by using a value
for base resistor R2 of about 1/2 the nominal value.

I am not entirely sure i understand that

Quote
Also, your values above may be wrong. Normally, the hFE value is "lower" for larger
collector currents.

What values are wrong? For the resistors, or the calculated current in the base and the the LED?

Quote
I'm curious why OP chose to switch the high side instead of using the original circuit. With this setup, the transistor is operating in the linear region and will never reach saturation.

So, there is actually a difference if the LED is in the collector side or the emitter side ?? :smiley-eek-blue:
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 09:59 pm

Quote
The link goes to a CircuitLab page that makes it easier to evaluate.

That's even more confusing. If you didn't know any better, you'd thing the 5V supply
on the collector was upside down, ;-). Possibly confusing to a noobee.
I'm not crazy about that schematic capture browser app.
Also, this is not good, pinouts between NP2222 plastic case and 2N2222 metal case
are backwards, oof! Murphy strikes again.
http://www.stanford.edu/class/ee133/datasheets/2n2222.pdf
http://www.jameco.com/Jameco/Products/ProdDS/38237ST.pdf
http://www.fairchildsemi.com/ds/PN/PN2222A.pdf

They look right to me. The base is in the middle where I expect it and the plastic part would fit in the standard TO-18 triangular PCB layout without having to cross the legs.

I congratulate OP for going through the design process. The first circuit is more common though, in my opinion.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 10:07 pm
Quote
So, there is actually a difference if the LED is in the collector side or the emitter side ??

Absolutely. When using an NPN transistor as a switch, it is more common to place the load on the collector side and drive the transistor into saturation so as to dissipate the least amount of power in the transistor. The way you have it, there is a couple of volts across the CE junction, not a problem really in this case because of the capabilities of the 2N2222 but something to think about.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: fungus on Feb 09, 2013, 10:20 pm

So, there is actually a difference if the LED is in the collector side or the emitter side ?? :smiley-eek-blue:

Yes. You only get 5V base->emitter when the emitter is connected to ground. If you put something in between emitter and ground then the emitter isn't at 0V.

Title: Re: A couple of questions on the 2N2222 transistor
Post by: CrossRoads on Feb 09, 2013, 10:29 pm
When the NPN emitter is grounded Vbe is ~0.7V and base resistor is easy to calculate:
(5V - 0.7V)/20ma = Rbase
20mA should put the C-E junction into saturation and let the transistor act like a switch, with the current limited by the resister in series with the LED.

When the emitter is connected to the load, then Vb becomes Vf + (I-load x Rload) + Vbe + (Ib (from the Arduino) * Rload)
Just messy.

You can look up "Collector follower" vs "Emitter follower" for more info.

Ideally, you would have NPN for sinking current, and PNP for sourcing current.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 10:45 pm
Quote
When the NPN emitter is grounded Vbe is ~0.7V and base resistor is easy to calculate:
(5V - 0.7V)/20ma = Rbase

I would think that if you were going to drive the base with 20mA, you might as well leave out the 2N2222.  :)
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 11:10 pm

Quote
They look right to me. The base is in the middle where I expect it and the plastic part would fit in the standard TO-18 triangular PCB layout without having to cross the legs.

I think the "round" part of the PN2222 body and the "curved" part of the 2N2222 pin
arrangement point in opposite directions, so if your pcb layout looks as follows, you're
up the creek [of course, I may be upside down over here],

The silkscreen may be misleading. All goes to reinforce the fact that you need to look at the data sheet.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: CrossRoads on Feb 09, 2013, 11:12 pm
I did not leave out hFE/beta, I was discussing driving the base hard so the device goes deep into saturation.
You want the current to be limited by the load resister and not the gain of the device
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 11:19 pm

I did not leave out hFE/beta, I was discussing driving the base hard so the device goes deep into saturation.
You want the current to be limited by the load resister and not the gain of the device

It is not necessary to drive a 2N2222 that hard to get it to saturate with a load of, say, 20mA. It saturates with 150mA of collector current with just 15mA of base current. Again, why use a transistor driver at all if you are going to use that much current from the Arduino?
Title: Re: A couple of questions on the 2N2222 transistor
Post by: CrossRoads on Feb 09, 2013, 11:26 pm
Yes, transistor a little silly for 1 LED, but the same design carries right over into 2-3-4 LEDs in series from 12V source.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 11:27 pm
Quote
OP, you notice how analog design is really still an "art" [meaning 1/2 subjective and
based upon personal experience, :-)].

While there can be some "art" associated with design of analog circuits, we're talking primarily about a digital switch here and the design procedure is not that mysterious.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 11:32 pm

Yes, transistor a little silly for 1 LED, but the same design carries right over into 2-3-4 LEDs in series from 12V source.

Well, I'm not going to argue with you about your "Hail Mary" design approach.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: Papa G on Feb 09, 2013, 11:43 pm

Quote
OP, you notice how analog design is really still an "art" [meaning 1/2 subjective and
based upon personal experience, :-)].

While there can be some "art" associated with design of analog circuits, we're talking primarily about a digital switch here and the design procedure is not that mysterious.

Unfortunately, although we're only building a digital switch, we're using an analog
component to do it, so we need to pay attention to the analog characteristics.
That's what all those resistors are for.

Well, my first job out of university was with Texas Instruments on their 7400 logic family team and I can assure you that all those ICs have transistors and resistors inside and the same design criteria that you use with discrete components apply. Technically speaking, a transistor in saturation is not an analog component.

I get your point, I just don't rely on magic when science will do the job.  :)
Title: Re: A couple of questions on the 2N2222 transistor
Post by: charis on Feb 10, 2013, 12:21 am
A newer version of the schematic then, incorporating some of the feedback. The simulator reports 13.5 mA at the LED and 430 ?A at the base for an hFE of 32. I didn't change the 10kOhm resistor of the base to 4.7kOhm as that would give an hFE of 16. It is still not entirely clear what the hFE should be and since it is a loose value anyway and the datasheet does not give the value of hFE for 5V i guess an approximate value of 30-70 should suffice.

https://www.circuitlab.com/circuit/gmmqaq/2n2222-led/
Title: Re: A couple of questions on the 2N2222 transistor
Post by: CrossRoads on Feb 10, 2013, 01:09 am

Look at the On Characterics on sheet 2.
With Ib of 15mA, the base-emitter voltage will be ~0.6V and the collector-emitter voltage will be ~0.3V.
Use those numbers to work the resister values.

(5V - 0.6V)/15mA = Base resistor
(5V - Vf - 0.3V)/20mA = LED resistor.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: westfw on Feb 10, 2013, 08:26 am
Quote
The simulator reports 13.5 mA at the LED and 430 ?A at the base for an hFE of 32.

No, no.  hFE is a characteristic of the transistor, not the overall circuit.  You're looking at the current gain of the circuit.
A major point of designing a transistor circuit is that you minimize the effects of variations in the characteristics of the transistors, since they can vary quite a bit.  So Rbase is chosen to limit the current in the base/emitter circuit, and Rled is chosen to limit the current in the LED through the Collector/Emitter circuit, and everything will work just swell as long as hFE is "much larger" than Ic/Ib
Title: Re: A couple of questions on the 2N2222 transistor
Post by: oric_dan on Feb 10, 2013, 08:23 pm

Quote
The simulator reports 13.5 mA at the LED and 430 ?A at the base for an hFE of 32.

No, no.  hFE is a characteristic of the transistor, not the overall circuit.  You're looking at the current gain of the circuit.
A major point of designing a transistor circuit is that you minimize the effects of variations in the characteristics of the transistors, since they can vary quite a bit.  So Rbase is chosen to limit the current in the base/emitter circuit, and Rled is chosen to limit the current in the LED through the Collector/Emitter circuit, and everything will work just swell as long as hFE is "much larger" than Ic/Ib

Excellent description of the situation.
Title: Re: A couple of questions on the 2N2222 transistor
Post by: kf2qd on Feb 11, 2013, 04:48 pm