Resistor selection for NPN (NP3904) base

Thread Starter

loadedmodg

Joined Jul 1, 2014
1
Hi all,

I see this posting about selecting a resistor for a different circuit but it doesn't explain to me what I need for this particular implementation. http://forum.allaboutcircuits.com/showthread.php?t=43775

What I'm looking for is a way to tell what resistor I need for a Raspberry Pi GPIO (3.3v out, up to 50mA) to NP3904 base.

I've heard horror stories of hooking up circuitry to the Raspberry Pi and frying the board and I'm hoping someone here could help before I get to that point.

I've selected an NP3904 (due to it being the only one available at RadioShack which would saturate at 3v). I currently have the base connected directly to the Raspberry Pi GPIO pin, the Collector to my load (12v), and the Emitter to common ground.

It works as-is, but I'm worried about tidying everything up and reattaching to the wall if I'm going to need to replace this when it burns up in the future. Here is the NP3904 datasheet http://www.fairchildsemi.com/ds/2N/2N3904.pdf

What am I looking for in order on that datasheet to figure out which resister I need in between the Raspberry Pi's GPIO and the base of the NPN?

Is there a way for me to figure this out on my own in the future?

Thank you for your time, I'd appreciate any help!
 

wayneh

Joined Sep 9, 2010
17,496
I assume you are using the transistor as a switch, meaning it will be at 2 states, on or off?

In that case the choice for the base resistor depends on the load current you expect. You want the base current to be about 10% of that load current. This will ensure the transistor is switched fully on (saturated), without allowing too much current to flow. Assume a 0.6V drop across base-emitter, and calculate the resistor value to give you the targeted base current.

If the base current needed by the transistor exceeds the specifications of your Pi, you'll need a darlington transistor (essentially 2 transistors in one package).

Once you get a build working, you can experiment and possibly increase the base resistor value to further reduce current.
 

crutschow

Joined Mar 14, 2008
34,284
.......................
I've heard horror stories of hooking up circuitry to the Raspberry Pi and frying the board and I'm hoping someone here could help before I get to that point.

I've selected an NP3904 (due to it being the only one available at RadioShack which would saturate at 3v). I currently have the base connected directly to the Raspberry Pi GPIO pin, the Collector to my load (12v), and the Emitter to common ground.
..................................
Connecting the transistor base directly to the output of the PI is one way to fry the PI. :eek: A BJT transistor base-emitter junction looks like a forward-biased diode and will draw essentially the short-circuit current from the PI output. You always want a resistor in series with a BJT base.
 

takao21203

Joined Apr 28, 2012
3,702
also digital MOSFETs can be used for that.

The resistor for the base depends on the load.

The hfE is quite high for 10mA (and similar) but lower for high currents.
The 2n3904 also can have quite a bit variation on this, mostly depend on the batch/brand.

Most small signal transistors have a hfE between 50 and 100, while larger transistors rather have a hfE of 20.

It depends if you want to use the transistor as amplifier, or if you want to saturate it with a high base current.

Digital MOSFETs also sometimes have a gate resistor but don't neccessarily need one. Most of them are SMD (sot23 etc), while 2n3904 also is available as TO92.
 

wayneh

Joined Sep 9, 2010
17,496
A BJT transistor base-emitter junction looks like a forward-biased diode and will draw essentially the short-circuit current ...
This makes perfect sense to me, but when I argued almost the same thing here, see post #3, I was assured I was wrong. I've been trying to reconcile things ever since. In that circuit, I predicted the capacitor would discharge thru the bases as if thru a short, and that the collectors of the transistors needn't even be connected.

I suppose this is a hijack. :cool:
 

takao21203

Joined Apr 28, 2012
3,702
Seriously, $1.49 for a single 2n3904??

Even for ten of them it'd be a high price.

I sell 50 pcs. at $1.70 (discounted, originally 1.89)

And still making profit.
 

crutschow

Joined Mar 14, 2008
34,284
This makes perfect sense to me, but when I argued almost the same thing here, see post #3, I was assured I was wrong. I've been trying to reconcile things ever since. In that circuit, I predicted the capacitor would discharge thru the bases as if thru a short, and that the collectors of the transistors needn't even be connected.

I suppose this is a hijack. :cool:
Sort of. The circuit your are referring to is an emitter-follower not a grounded-emitter which is a different animal. As long as the transistor is in the active region (collector connected) then the input impedance is high, being roughly equal to the Beta of the (Darlington) transistor times the emitter resistor value.

If you don't connect the collector, making the transistor not active, then you will see a low input impedance, looking like diodes in series with the emitter resistor.
 
Last edited:

Alec_t

Joined Sep 17, 2013
14,280
Raspberry Pi GPIO (3.3v out, up to 50mA)
If your resistor value is greater than 100 Ohms you should be safe. 3.3V can drive a maximum current of 33mA through that; well within the spec for the GPIO port.
 

takao21203

Joined Apr 28, 2012
3,702
I built a transistor tester some while ago, with adjustable base current.

Of course there has to be a 512 Ohms limiting resistor, or you get undesireable operation (or at least not as intended). Yes larger currents will flow into the base (and out of it for PNP), if you dont limit the current.

Even with just a joulethief and a 1.2v battery as supply, a few LEDs, a 3M IC socket, and some adjustable potentiometers (as well a few resistors), I was able to learn a lot about the behaviour, and with the tester (it has DIL switches) I can figure out the pin configuration too.

Anyone who really want to understand transistors should build a simple tester.
 

SgtWookie

Joined Jul 17, 2007
22,230
3.3v / 50mA = 66 Ohms, so if you used any greater resistance from the output to ground or +3.3v, you would be within limits for ONE output. You need to keep in mind the TOTAL I/O limits; see the documentation for the I/O device to determine what the maximum total I/O source/sink current is.

While the 2n/PN3904 has a maximum collector current rating of 200mA, the practical limit is about 1/2 that much, or 100mA. Look at any datasheet for those transistors, and you'll see that the plots seldom go above 100mA.

When using a transistor as a common-emitter saturated switch (with the load on the collector), you completely ignore the stated beta/gain ranges for the transistor, and use a "forced" beta of 10; so basically (sic) you will need 1/10th of the base current as you need to sink via the collector. Since the '3904 has a practical maximum Ic of 100mA, and we're using a forced beta of 10, you will not require more than 10ma base current for this transistor.

I'll estimate that Vbe will be roughly 0.8v when Ib=10mA, and also that your Vout from your PI will be around 3.2v when sourcing 10mA, which is probably a tad optimistic.

Rbase ~= (Vout-Vbe) / (Ic / beta)
Rbase ~= (3.2v - 0.8v) / (100mA / 10)
Rbase ~= 2.4 / 10mA
Rbase ~= 240 Ohms
Here is a decade table of standard EIA resistance values:
http://www.logwell.com/tech/components/resistor_values.html
Bookmark this page!
You will see that 240 Ohms is a standard E24 value. You could use 220 Ohms if need be.

You might be able to use a logic-level N-channel enhancedl MOSFET, however it should have an Rds(on) rating at 3.3v. Do NOT go by the threshold voltage!

FYI, Radio Shack also carries an assortment of 15 NPN transistors for around 3 bucks. In the old days, the package used to contain a very random assortment of TO-92 transistors, usually of Asian origin. Nowadays, you almost always get:
Five PN3904, rated 200mA Ic, but for practical purposes good for up to 100mA
Five PN4401, rated 600mA Ic, but for practical purposes good for up to ~300mA
Five PN2222, rated 800mA Ic, but for practical purposes good for up to ~500mA

The PNP assortment comes with a complementary assortment:\
Five PN3906, complement to PN3904
Five PN4403, complement to PN4401
Five PN2907, complement to PN2222
 
Last edited:
Top