Struggling with 2N3906 - Page 1
Forum section: electronics / beginners

author: dynek
author_rank: Contributor
timestamp: March 12, 2022, 08:03:15 am
content: Hello everyone, this is my first message here.I'm not a total noob, rather an enthusiastic and motivated engineer, self-taught, hence I probably lack some basics.For a project I'm building, I absolutely need to switch a LED on and off from high-side (no choice unfortunately).Moreover, it's a 12V LED inside a push button (with resistor) that must be turned on/off using a 3.3V gpio.I used a 2N3904 to pull the 2N3906 to GND and it works fine like this:Now I was checking a few things, and noticed the 2N3906 is never 100% off, I simplified the setup to this and multimeter always shows 0.5/0.7V, no matter the value of R1.Any idea why?Thank you!

author: retiredfeline
author_rank: Frequent Contributor
timestamp: March 12, 2022, 08:10:15 am
content: Your E and C of the 3906 are swapped. Its BE junction is probably in reverse breakdown mode. Remember, the emitter arrow shows the normal direction of current.

author: dynek
author_rank: Contributor
timestamp: March 12, 2022, 08:23:39 am
content: You're right :-)Thanks a bunch, much appreciated I correct my schematic.I see on the web that some seem to add a resistor between E and B.Would it be any useful in my situation, where gpio has a pull down (ESP32), so base of Q2 will not be low except if gpio is set high.

author: retiredfeline
author_rank: Frequent Contributor
timestamp: March 12, 2022, 08:41:35 am
content: For Q2, no, the GPIO will drain the current, unless you set the output to HiZ. For Q1 can't hurt in case you get a slightly leaky transistor and the µA get amplified and only a small amount of current is needed to light up LEDs these days.

author: Zero999
author_rank: Super Contributor
timestamp: March 12, 2022, 09:44:18 am
content: Try this arrangement.

author: m3vuv
author_rank: Super Contributor
timestamp: March 12, 2022, 09:49:00 am
content: am i right in thinking the collector of an pnp should point towards the -ve rail and an npn +ve?

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 12, 2022, 09:54:59 am
content: pnp wants current flowing like emitter->collector and emitter->base.So it's great for making high side switches. Any lower voltage than Ve-0.6 at the base will cause current flow at turn on the transistor.

author: tooki
author_rank: Super Contributor
timestamp: March 12, 2022, 10:01:48 am
content: Quote from: m3vuv on March 12, 2022, 09:49:00 amYes, except that instead of thinking of it as pointing towards a rail, think about it pointing towards the lower or higher voltage, respectively.

author: dynek
author_rank: Contributor
timestamp: March 12, 2022, 12:21:10 pm
content: Quote from: Zero999 on March 12, 2022, 09:44:18 amI have always seen & put resistor before the base to avoid the GPIO to burn and since it's working now that I switched C & E, I'm reluctant to try and burn the chip

author: dynek
author_rank: Contributor
timestamp: March 12, 2022, 12:24:13 pm
content: Last question about this, I think :-)How can I determine the right value for R2 ?I must admit I tested some value until it worked, but there's obviously a way to calculate the right value?

author: retiredfeline
author_rank: Frequent Contributor
timestamp: March 12, 2022, 12:27:07 pm
content: Divide load current by minimum gain expected of transistor. That will be the base current you need. From ohms law calculate the resistance. And you have posted the unfixed circuit again.

author: MarkF
author_rank: Super Contributor
timestamp: March 12, 2022, 04:31:51 pm
content: Your circuit is still not correct.Try something like this:The emitter and collector of Q2 are still reversed in your last circuit.You want the emitter of Q1 to be tied directly to GND. If it went through a resistor, the emiiter voltage would rise when the GPIO voltage went high. Possibly VBEwould not turn ON the transistor.Resistor R1 limits the current from the GPIO pin.You want R2 to go to 12V in order to turn OFF Q2 when the GPIO pin is low. The way you have it Q2 may not turn OFF since it doesn't pull the base up to the emitter voltage.The voltage divider created by R2 and R3 set the base voltage of Q2 when turned ON. For a 2N3906 the max VBEis 5V.Resistor R3 will indirectly limit the current through Q2. So, you would need to adjust the R2 and R3 voltage divider to supply at least what current the load needs and the max current capable by Q2.LEDs do not have a built-in resistor. Resistor R4 is to limit the LED current. In this case assume a white LED with a forward voltage of 3V and with a 10mA current, resistor R4 should be approx 900Ω.

author: magic
author_rank: Super Contributor
timestamp: March 12, 2022, 04:40:25 pm
content: Small correctionQuote from: MarkF on March 12, 2022, 04:31:51 pmThe circuit posted by Zero999 is correct and works. Base voltage becomes 3.3V or whatever the GPIO output is, then the emitter is at 2.7V due to emitter follower action and current sunk by Tr2 is simply 2.7V / R2.That circuit has the advantage of needing only two resistors, and a disadvantage of offering less protection to the GPIO in the unlikely event that something bad happens to Tr2 and it shorts out between base and collector.Quote from: MarkF on March 12, 2022, 04:31:51 pmThat's the maximumreverseVbe. But you aren't applying voltage in reverse, but forward. Forward Vbe is limited to ~0.7V by the BE junction. You only need to care not to exceed some sane maximum base current. A few mA is alright.Quote from: MarkF on March 12, 2022, 04:31:51 pmSome LEDs have built-in current limiting resistors. They are meant to be powered from a particular voltage source like 5V or 12V.

author: dynek
author_rank: Contributor
timestamp: March 12, 2022, 05:07:36 pm
content: Quote from: retiredfeline on March 12, 2022, 12:27:07 pmMy bad it's because I re-used the same image I posted in my initial message.

author: dynek
author_rank: Contributor
timestamp: March 12, 2022, 05:10:57 pm
content: Quote from: MarkF on March 12, 2022, 04:31:51 pmWell in this case it's a push button, and the manufacturer says there's no resistance required because it's built-in.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 12, 2022, 05:12:03 pm
content: Two ways to think about it:- The emitter arrow points in the direction of conventional current flow. So, it points down, the usual way you draw a circuit. Putting the PNP emitter at the top, and NPN emitter at the bottom. Or if you're using it sideways, whichever side is higher or lower, respectively. (This is a common-emitter amplifier/switch application, so it simply ties to the respective supply rail.)- The emitter goes to common. You can take any discrete circuit, swap all NPNs and PNPs, flip all diodes, and flip all polarities -- so now the negative supply is at the top, and positive ground is at the bottom. Indeed, circuits were drawn precisely this way, back in the days of germanium transistors (almost all PNP): coming from the tradition of vacuum tubes (essentially N-type devices as well), this made sense, with all the same layouts and signal flows and stuff, if you just don't mind that the supply is backwards.At this point, you can simply flip the circuit and put positive on top again, which will have the effect of putting emitters and diodes in the correct places.Here's a demonstration of the polarity and circuit flip:The subcircuit encircled is a constant current source. The R+D between B-E on the left serves as temperature compensation and makes it somewhat more accurate to set; the lone R5 is acceptable if you don't mind the tempco or offset.Regarding the OP circuit, it's not wrong, in a sense -- it's just that transistors are almost never symmetrical. You might not've noticed a difference at all using a germanium transistor, for example (they were typically alloy junction types, which are symmetrical). It is P-N-P after all, it shouldn't matter, right? Well, to an extent that's true. What happens is two things:1. E-B breakdown voltage is fairly low; rated at 7V and apparently good for a few volts more in your case. Note they only give a minimum; it can be more, and varies between individual parts. But within this voltage range, say you use a 5V supply, yup, works just fine, you might not've noticed anything at all! Except for...2. hFE is lower. A lot lower, usually single digits. The way asymmetrical junctions are made, current prefers to flow through the device in one direction (technically, due to a doping gradient). Although, there is still some application for this "inverted" operation: Vce(sat) can be very low, a few mV at low currents (versus the 20+ mV in the normal direction -- the price paid, literally, for the assist given by the doping gradient). So if you don't mind driving the base relatively hard (to get it to saturate with the low hFE), this can be a use case. (Largely irrelevant since the 60s-70s, when MOSFETs took over for the same applications -- hard to have a voltage drop when you've got a true resistance Rds(on).)Interestingly, there are "low Vce(sat)" transistors, which have conventional Veb ratings, yet extremely high inverted hFE (often over 100); this is part of how they achieve the low Vce(sat). To optimize forward Vce(sat), you must optimize both polarities, it seems.There are also "muting" transistors, with higher Veb and reasonable inverted hFE, used for -- as the name suggests -- muting audio circuits electronically: that is to say, analog switches. These probably peaked in the 70s-80s? They're quite rare nowadays.So, just a little neat background information about this use. It seems wrong, and, well, for the most part it is, but not because it's bad, it's just different. Not usually different in a useful way, mind -- but there have indeed been uses of those remaining niches.Tim

author: tooki
author_rank: Super Contributor
timestamp: March 12, 2022, 05:12:34 pm
content: Quote from: MarkF on March 12, 2022, 04:31:51 pmExcept when they do, which is really common in things like industrial automation. The OP clearly said, right in the opening post:Quote from: dynek on March 12, 2022, 08:03:15 am

author: Zero999
author_rank: Super Contributor
timestamp: March 12, 2022, 07:22:22 pm
content: Quote from: dynek on March 12, 2022, 12:21:10 pmWhy would it burn the GPIO? The current through Q1's base will be tiny.The advantage of this configuration is, there's only one resistor value to calculate. Q1's base current is intrinsically limited by R2, which is on the emitter and IB= IC/hFE.The only time I'd add a base resistor is if there's a risk +V could be disconnected, whilst the microcontroller is still powered and R2 is low enough to draw to draw enough current to damage it. In this case I'd choose a low value such as 1k.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 12, 2022, 08:24:59 pm
content: A downside is Tr2's collector only pulls down to V(Input) - Vbe + Vce(sat).For +V >> V(Input), no problem.It's interesting because of two things:1. Tr2 collector voltage swing is tiny, just the Vbe of Tr1. This makes it very fast: no time waiting for Tr2 collector capacitance to dis/charge. Switching speed is limited by Tr1 storage time (which R1 discharges, so speed depends on its value relative to load current).2. Tr2 collector voltage can be basically anything, as long as it's greater than the above limit. This makes the arrangement excellent for level shifting: +V could be 6V, 12V, 100V -- as long as the transistors are rated for the voltage, and what power they'll drop (Tr2 mainly), it'll do, no adjustment needed.Tim

author: strawberry
author_rank: Super Contributor
timestamp: March 12, 2022, 08:58:02 pm
content: with mirror better stability

author: Zero999
author_rank: Super Contributor
timestamp: March 12, 2022, 10:28:24 pm
content: Quote from: strawberry on March 12, 2022, 08:58:02 pmBut now the current through the load is limited to only 20mA, rather than the full 235mA

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 12, 2022, 10:51:03 pm
content: Mirror circuit just for driving a damn led, really?Quote from: dynek on March 12, 2022, 12:21:10 pmIt's a different configuration, you can't burn the pin because the transistor gain will multiply the current flow from the base over the emitter resistor, causing voltage drop and self-limiting.I(emitter) = V(base)-0.6 / R(emitter)I(base) = I(emitter) / hfeFor R=120Ohm, Vb=3.3V and hfe=100:I(emitter) = (3.3-0.6)/120 = 22.5mAI(base) = 22.5/100 = 225uAIf the collector is disconnected, then hfe would be 1(No current gain), all current would be taken from the base, still 22mA won't burn the pin easily.Anyways 22mA at the pnp base is a lot for driving a led, unless it's a high current one.I'd go with 1K, drawing 2.7mA from the pnp base, * 100hfe it would drive 270mA which is more than enough for a led.Or even 2k2...4k7.

author: Zero999
author_rank: Super Contributor
timestamp: March 13, 2022, 08:44:40 am
content: Quote from: DavidAlfa on March 12, 2022, 10:51:03 pmThanks for posti8nbg all the calculations. I would've done the same, but I have a broken arm and I don't have the patience to make long posts, at the moment.QuoteThe original poster didn't say what the load is, so I assumed it was a high power LED, such as an LED strip.I would recommended using a forced beta of much less than hFEis often specified when VCEis unacceptably high, often more than 1V. The general rule of thumb is IB= IC/10, but that's normally a bit overkill.Anyway,I didn't look at the data sheet for the 2N3906, which is only rated to 200mA, yet my circuit puts 235mA through it, but the original poster now has enough information to design the circuit for the load he's powering.https://www.sparkfun.com/datasheets/Components/2N3906.pdf

author: tooki
author_rank: Super Contributor
timestamp: March 13, 2022, 11:56:55 am
content: Quote from: Zero999 on March 13, 2022, 08:44:40 amYes, they did, right in the opening post:Quote from: dynek on March 12, 2022, 08:03:15 amSo while no specific current is mentioned, you certainly have an idea of the ballpark.

author: Zero999
author_rank: Super Contributor
timestamp: March 13, 2022, 03:05:50 pm
content: Quote from: tooki on March 13, 2022, 11:56:55 amIt's pretty meaningless, as the current wasn't mentioned.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 13, 2022, 04:29:33 pm
content: Ahh I know these 5w leds inside push buttons...

author: dynek
author_rank: Contributor
timestamp: March 13, 2022, 06:48:20 pm
content: I guess my power supply isn't sensitive enough, it says 0.000A. But we may safely assume 5 / 10mA I'd guess ?Now I'm still unable to calculate R2 (base of 2N3906 in my setup)Quote from: retiredfeline on March 12, 2022, 12:27:07 pmMeaning I should divide 0.005A by 100 (hfe) then 12 by 0.00005 = 240kΩ ?

author: Zero999
author_rank: Super Contributor
timestamp: March 13, 2022, 07:55:21 pm
content: Why not just use a single NPN transistor?

author: magic
author_rank: Super Contributor
timestamp: March 13, 2022, 08:19:47 pm
content: You guys would save yourselves plenty of time if you read the original post carefully

author: Zero999
author_rank: Super Contributor
timestamp: March 13, 2022, 09:08:41 pm
content: Quote from: magic on March 13, 2022, 08:19:47 pmI did, but had forgotten about it when I made the previous post.Quote from: dynek on March 13, 2022, 06:48:20 pmR1 = 47kR2 = 4k7There's no need for a base resistor on Tr2. If +V is disconnected, the GPIO current will be only 600µA.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 13, 2022, 11:20:27 pm
content: Why R1?You don't need to control TR2 gain, neither very fast switching, it's just a led.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 13, 2022, 11:46:39 pm
content: I think you'll find without R1, the LEDs glow dimly, and much more at elevated temperature.Easy insurance to keep it off.Tim

author: retiredfeline
author_rank: Frequent Contributor
timestamp: March 14, 2022, 12:02:10 am
content: Quote from: dynek on March 13, 2022, 06:48:20 pmUnless you need to conserve every bit of battery life, you can be conservative and use a figure of say 20 for the hfe which will give you a value of about 40k. The current in that would only be 1/20th of that through the LED anyway.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 14, 2022, 03:14:33 am
content: For that matter, I don't have a problem with using hFE(sat) in the range of 50 or so. More is justifiable for types with higher hFE in general, of course -- indeed the likes of PBSS303NX is even specified at hFE(sat) = 100, even up at Ic = 4A (out of a 5A/10A rating; despite its small size, it's a beefy transistor!). 2N3906 of course doesn't perform nearly so well, so a more modest figure in the 20-50 range is about the most you'd want to use. Higher hFE types like 2N5087, BC857, etc. would be applicable for an application like this. (Though given the age of 2N5087, it might have a soft saturation region, i.e., hFE falling steeply for Vce of several volts, rather than tenths thereof. BC857 looks pretty ordinary though.)Also, nothing wrong with using a MOSFET with hFE --> ∞.Size thebasegate resistor for a modest voltage drop (say 5-10V; 3 or so minimum?).Tim

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 14, 2022, 06:00:15 am
content: BC547C / 557C are very common, introduced +20 years ago, hfe >400, yet I keep seeing these ancient transistors everywhere on the forum.Just, why?Yep, you could replace tr1 by any p-ch fet.I'd increase R1 to 100K and R2 to 10K to save some power.

author: m3vuv
author_rank: Super Contributor
timestamp: March 14, 2022, 06:21:49 am
content: they turn up because they are inexpensive readily available and they work,its like the old saying "dont fix it unless its broke",in my case its more like keep fixing it untill its broke!! lol.

author: Zero999
author_rank: Super Contributor
timestamp: March 14, 2022, 08:24:02 am
content: How many LEDs are there? If they're more than two, then how about using a CMOS level shifting IC such as the 4504B.https://www.renesas.com/eu/en/document/dst/cd4504bms-datasheet

author: tooki
author_rank: Super Contributor
timestamp: March 14, 2022, 05:25:07 pm
content: Quote from: Zero999 on March 13, 2022, 03:05:50 pmNo, it isn't. A button isn't going to be illuminated with a retina-searing 5W LED, as DavidAlfa already said. You may not know if it's 20, 40, or 100mA, but you know damned well it's not going to be 500mA or a whole amp.Buttons rarely have more than 2 LEDs in them, and with modern LEDs being so bright, two of those at 20mA each is enough for most situations. I just looked at a few industrial buttons, and their illumination modules are designed for 20mA.