NPN with no base resistor to drive an LED from a GPIO - Page 1
Forum section: electronics / beginners

author: DrG
author_rank: Super Contributor
timestamp: January 22, 2021, 05:56:28 pm
content: I have a project in which I need the microcontroller to flash an LED as an alarm. This is the LEDhttps://www.nteinc.com/specs/30000to30099/pdf/nte30030_36_44.pdfhigh brightness but nothing special. Edit: The one I am using is NTE30034 Red Ic max 25mA Vf max 2.5VWithin my KSAs, if I were working with a board like an Arduino UNO I would just have the GPIO drive the LED through a current limiting resistor (something like 330).If I needed more current than the GPIO could provide, I would use an NPN transistor as a switch - as illustrated on the left. I have understood that it is desirable to use the NPN in saturation mode, i.e., so it is fully on or fully off. OK, I got that. The microcontroller is a Teensy 4 and, at most, the GPIO can source 7 mA. So, I was all set to breadboard the tried and true design on the left.I was just surf-reading and came across this designhttps://electronics.stackexchange.com/questions/60865/how-to-drive-a-20ma-led-from-a-4ma-max-gpio-pinand, on the right, is what I have breadboard using the shown components. It seems to work well.The author was kind enough to provide an explanation and I think I understand. I was reluctant at first because of a perceived rule to operate an NPN switch in saturation mode.My question is simply; is there a disadvantage to doing it this way? Am I missing something?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 22, 2021, 06:01:06 pm
content: It better be a red LED.The emitter follower (right) loses ~0.7V base-emitter, the same voltage that you need to limit current into on the left (common emitter) circuit. In addition, the GPIO pin will drop some voltage, depending on load current, so maybe it'll only pull up to 3.2 or 3.1V. That doesn't leave much for the current limiting resistor, and restricts use to red LEDs only (Vf ~ 2V).If you need to run blue or white LEDs, even the 3.3V supply is marginal.A 2N7002 or BSS138 can be used in the left circuit, with no base/gate resistor (although ~100 ohms is still recommended) and with no restriction on GPIO current or saturation voltage.Tim

author: DrG
author_rank: Super Contributor
timestamp: January 22, 2021, 06:10:25 pm
content: Quote from: T3sl4co1l on January 22, 2021, 06:01:06 pmThanks. Yes, it is red.

author: Peabody
author_rank: Super Contributor
timestamp: January 22, 2021, 06:35:15 pm
content: If it works for you, the follower circuit has the advantage that even the base current is used to power the LED. That's as opposed to the circuit on the left where the base current is "wasted". But you might want to get your meter out and measure the voltage at various points in the circuit to make sure you understand how it works. Of particular interest is the voltage drop across the resistor, which tells you how much current the circuit is actually drawing.I guess I should also say that modern LEDs can be super efficient, so you might want to just test yours to see if they are bright enough when powered directly from the GPIO pin, with a resistor.

author: S. Petrukhin
author_rank: Super Contributor
timestamp: January 23, 2021, 12:29:00 am
content: Signal LEDs, if they are not lighting LEDs, operate at very low current. In my practice, there is a replacement of resistors designed for a current of 3mA, with others so that the current is 0.5 mA because they literally blinded. If this is the use of a pin only for driving the LED, a transistor is not required here in my opinion. Check whether the brightness of the glow at 1mA is enough for you and calculate the resistor for direct connection to the pin.

author: MIS42N
author_rank: Frequent Contributor
timestamp: January 23, 2021, 09:39:33 am
content: Nothing wrong with the Q2 circuit. If anything it should work better, Q2 will saturate quickly as soon as the LED conducts. As long as the GPIO is rated to discharge the base capacitance at turn off. If you are open to alternates, I think a 2n7000 FET would work as Q1 and does not need a resistor on the gate. Has the advantage of a lower voltage drop so the current limiting resistor will have better control (IMHO).

author: Ian.M
author_rank: Super Contributor
timestamp: January 23, 2021, 09:53:55 am
content: There's another nice circuit if you've got a supply rail that's at least the LED (or LED string) Vf drop above MCU Vdd. Start with your right-hand circuit, but move the LED to in series with the collector and power it from a higher voltage rail. Now the emitter resistor sets the current as (Vdd-Vbe)/Re, and the transistor acts as a switched constant current sink, as long as its collector is at or above Vdd.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 10:09:39 am
content: Quote from: MIS42N on January 23, 2021, 09:39:33 amQ2 will not saturate, because it's an emitter follower.

author: MIS42N
author_rank: Frequent Contributor
timestamp: January 23, 2021, 10:55:49 am
content: Quote from: Zero999 on January 23, 2021, 10:09:39 amYes I didn't explain it well. Without a resistor between GPIO and Q2, the base capacitor is quickly charged when the LED conducts, a quicker turn on than Q1 achieves as it has to charge through R1. Turn off is even faster as the capacitance is between 3V3 and GPIO low. I really meant Q2 would switch faster than Q1. My bad.

author: wolframore
author_rank: Newbie
timestamp: January 23, 2021, 04:44:26 pm
content: What a clever circuitKeep in mind the current is not dependent on supply voltage but it will be affected by Vfd so different LED different current, but very clever, current gain.

author: tooki
author_rank: Super Contributor
timestamp: January 23, 2021, 04:59:28 pm
content: Quote from: T3sl4co1l on January 22, 2021, 06:01:06 pmOr yellow, or traditional green, all of which will light at under 2V. Only blue (and by extension white) and modern emerald (“true”) green LEDs have appreciably higher forward voltages.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 23, 2021, 05:17:49 pm
content: Yeah, green is marginal, but still okay.Note the distinction -- "traditional" GaP green has an acceptable voltage drop (about 2.2V), high efficiency (GaInN) green does not!Amazingly, GaP is so inefficient (or, at least, so much harder to optimize?), that it pays to use a higher voltage material entirely (GaInN is ~3V, normally emitting cyan to ultraviolet depending on exact composition), using either a microstructure or a phosphor to make green out of it (I forget how they do it exactly). Consequently, the green is a little different, usually more pure or "lime-green"-ish, in comparison to the slightly yellowish green of GaP. It's close enough you wouldn't notice independently, but side-by-side it's pretty obvious. Cool, huh?Tim

author: DrG
author_rank: Super Contributor
timestamp: January 23, 2021, 06:10:13 pm
content: Thanks much for the responses, I appreciate them. I have incorporated the circuit as shown into the project and it works fine. I am always glad to use what I have on hand. I feel a little more secure with my understanding and don't think there are any surprise disadvantages. As noted in the author's description and here, the 700 mV drop is an important qualifier with regard to LED choice, especially with 3V3 as I am using. The Vf on my red LED works fine and so for this project, I am happy with the circuit.Maybe I am taking advantage of some thread drift allowance, but I re-examined another circuit with respect to a better understanding of an NPN in an emitter-follower configuration....A while ago, I bought a couple of these active piezo buzzers - can't remember where I got them, but they are listed here, for examplehttps://www.aliexpress.com/item/4000241319430.htmlI traced out the circuit as this (I drew it as 3V3 Vcc which I have tested them with but the advert listed 3V3-5V as I recall):The three pin J3Y is listed as an NPN, e.g.,https://www.sunrom.com/p/s8050-j3y-npn-sot-23-smd-05a-40vand I think I got the two resistors correct as I recall using a meter on them to verify the values.Why did they use R1? Why not connect the collector directly to the GPIO as in the above?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 23, 2021, 06:34:38 pm
content: The series resistor tends to prevent oscillation, and also allows for 5V logic on a 3.3V supply (the B-C junction gets forward-biased, clamping the base at ~4.0V).Ed: here's the transistor by the way:https://www.openimpulse.com/blog/wp-content/uploads/wpsc/downloadables/S8050-NPN-Transistor-SOT-23-Datasheet.pdfTim

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 06:51:21 pm
content: It's not a piezo, but a magnetic buzzer. A piezo is high impedance so can be driven directly from a microcontroller output. That circuit won't drive a piezo very well, because a piezo is capacitive and would require a resistor in parallel, to discharge it.

author: DrG
author_rank: Super Contributor
timestamp: January 23, 2021, 06:56:19 pm
content: Quote from: Zero999 on January 23, 2021, 06:51:21 pmHmmm I can see the piezo element through the hole - no?

author: rsjsouza
author_rank: Super Contributor
timestamp: January 23, 2021, 07:04:33 pm
content: Just a remark: if the GPIO is 3.3V TTL compatible, anything down to 2.4V is still considered a logic level "1", causing the circuit on the right to not function.I didn't check the device/board datasheet.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 07:14:12 pm
content: Quote from: DrG on January 23, 2021, 06:56:19 pmAre you sure? Although it's possible to get piezo transducers in that package, it's more likely to be magnetic, given the circuit. There's no way of telling, just by looking at the front. I've opened one of those up before. It's typically a steel disc on top of a circular magnet, surrounding an electromagnet.You can tell by measuring the resistance between the pins. If it's piezo, it should read open circuit. A magnetic transducer will have a much lower resistance: from hundreds to a few thousand ohms.https://hackaday.com/wp-content/uploads/2016/10/piezo-not-piezo-elektro-028_v1.jpghttps://www.slideshare.net/emilycalvin/operating-principle-of-magnetic-transducerhttps://www.cuidevices.com/blog/buzzer-basics-technologies-tones-and-driving-circuits

author: ledtester
author_rank: Super Contributor
timestamp: January 23, 2021, 07:14:41 pm
content: Well... a google search for "yxdz buzzer" yields a lot of results for "piezoelectric ceramic buzzer".But, if you go to this website:http://www.xhyxdz.com/and select their "electromagnetic active buzzer" offerings (I used Chrome's auto-translate feature), you see a lot of products which look like the buzzer in the photo. On the other hand, their piezo passive and active products don't have the same packaging. In particular, they don't have "YXDZ" imprinted on the case like you see on their their active magnetic products.

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 07:22:49 pm
content: Unfortunately many sellers don't know the difference and will sell a magnetic buzzer, as a piezo and probably vice versa. I found a hackaday article about a "fake piezo" which was actually magnetic, messing with the compass. It has the same picture, as I linked to above.https://hackaday.com/2016/10/20/navigation-thing-four-days-three-problems-and-fake-piezos/

author: DrG
author_rank: Super Contributor
timestamp: January 23, 2021, 07:30:38 pm
content: Quote from: Zero999 on January 23, 2021, 07:14:12 pmWell, I think it is, but I would not bet on it nor bet on my correct use of the nomenclature.Above is a pic that I just took that shows (L to R) run-of-the-mill piezo element buzzer (which does require additional circuitry which is inside the case I think) - it draws 15 mA to 24mA (3V3-5V) and has a "somewhat, fixed frequency. In the middle is a piezo element. This requires additional circuitry to drive (sometimes used for vibration detection as it is with a voltage out, but as a buzzer, you need a driver). On the right is a tiny magnetic speaker (took that from a toy that operated at 3V as I recall.I think that the board that I posted originally, is a piezo buzzer (as in the above pic, left that has internal driver circuitry) WITH the additional circuit as discussed that is on the board.I could be wrong and I suppose that I could unsolder it and hook it up directly to 5V and G, but that is my understanding at the moment.

author: Ian.M
author_rank: Super Contributor
timestamp: January 23, 2021, 07:38:42 pm
content: An electromechanical magnetic buzzer would have the same DC resistance in both directions. A transistor oscillator one or a transistor oscillator + piezo buzzer wouldn't. A magnetic buzzer can be expected to deflect a compass needle more than a piezo one as it will contain more/larger ferromagnetic parts, and may have an actual magnet, though as its common to put an inductor in series with a piezo transducer to boost the excitation voltage, this may not be conclusive,

author: Zero999
author_rank: Super Contributor
timestamp: January 23, 2021, 07:48:18 pm
content: Ian is correct, it can be tested with a magnetic compass. Another option is to carefully place a steel pin in the sound hole: if it's magnetic, it'll stick somewhat. The picture on the right is just a magnet from a speaker.

author: DrG
author_rank: Super Contributor
timestamp: January 23, 2021, 07:54:15 pm
content: I wonder if an android magnetometer app would work?

author: wraper
author_rank: Unknown
timestamp: January 23, 2021, 07:59:21 pm
content: Do not forget that when you have marginally enough voltage for LED, current through it may become unstable and there may be high brightness variation depending on temperature and particular LED specimen used, as there is some variation. It may be that voltage drop over current limiting resistor is so low that it say changes twofold (and so is current) depending on particular LED and/or ambient temperature.

author: DrG
author_rank: Super Contributor
timestamp: January 23, 2021, 09:43:30 pm
content: Quote from: DrG on January 23, 2021, 07:54:15 pmFromhttps://www.islproducts.com/design-notes/piezo-buzzers-vs-magnetic-buzzers/:Here is a piezo buzzer, note the lack of a magnet. This is what I thought that I was dealing with and others have disagreed.Here is a magnetic buzzer, note the presence of a magnet.So, I tested out whether the magnetometer inside my cheap phone could use an apphttps://play.google.com/store/apps/details?id=com.tuber.magneticsensor.magneticfield&hl=en_US&gl=USwhich claims "detects the magnetic field around you and measures the magnetic field accurately. " providing a value μT (micro Tesla).First, a baseline measure:Next, that little magnetic speaker that was included on the right of that three component picture and we can easily see there is a big-ass magnet there...and the buzzer that was included on the left of that three component picture...and finally, with all the drama of the big reveal of whether "you are the father"..... the actual buzzer board that started this great investigation.The only conclusion that I can draw, apart from my future in ghost detection, is that it IS a magnetic buzzer [and the crowd goes wild]

author: tooki
author_rank: Super Contributor
timestamp: January 26, 2021, 07:45:12 pm
content: Quote from: T3sl4co1l on January 23, 2021, 05:17:49 pmYes! (Heck, I still think LEDs are hella cool, even though they’re nothing new to me.)To me, the difference in color between GaP green (which I describe as lime green) and GaInN green (which I describe as “emerald”) is striking. I can readily tell them apart independently. (But I am very, very good at color perception in general, apparently.)I’ve never seen a green GaInN with phosphor (as in, I know they exist, I just haven’t seen one with my own eyes in real life), all the ones I’ve gotten have a bare die. So if the bandgap alone isn’t responsible for the color, it’s some other clever modification to the diode itself.I once bought a cheap pack of “ice blue” (i.e. cyan, no phosphor) LEDs from China, and while it was evident that no meaningful binning had taken place, it was interesting that the range of colors within it ranged from a kinda cerulean blue all the way to turquoise with a distinct green tinge!

author: tooki
author_rank: Super Contributor
timestamp: January 26, 2021, 07:52:13 pm
content: Quote from: Zero999 on January 23, 2021, 06:51:21 pmIn that same style of housing (which exists in various sizes), you can get both piezo and electromagnetic buzzers, both passive (i.e. just the transducer, which you must drive yourself) or active (with a complete driver built in, needing only a DC voltage to be applied). All four types are visually indistinguishable from the outside.

author: Zero999
author_rank: Super Contributor
timestamp: January 26, 2021, 09:19:23 pm
content: Quote from: tooki on January 26, 2021, 07:52:13 pmTrue, but my judgement was not based on the appearance, but by the circuit. I did say that both types can be found in that package style.Quote from: Zero999 on January 23, 2021, 07:14:12 pmQuote from: tooki on January 26, 2021, 07:45:12 pmIt depends on the drive current. GaInN green LEDs, not the phosphor ones, have a positive frequency vs forward current coefficient, so they tend to look more bluish, at higher drive currents and will go cyan if heavily overdriven. They do have a slightly lower forward voltage, than blue LEDs, but not by much.I have seen the phosphor green type. They're often sold for use in grow lamps.

author: tooki
author_rank: Super Contributor
timestamp: January 31, 2021, 07:57:07 pm
content: Quote from: Zero999 on January 26, 2021, 09:19:23 pmYes, I’m aware of that coefficient, but what does that have to do with what I was saying about the variation within one batch of cyan LEDs (as well as the existence of cyan LEDs)? They weren’t “heavily overdriven” green LEDs, they’re cyan at normal couple-of-mA current. As I said above, I’m very good at color perception, so I am not calling green GaInN “cyan”, I’m talking about a color clearly in between blue and green.Quote from: Zero999 on January 26, 2021, 09:19:23 pmThat makes NO sense: plants are green because theyreflectgreen light. So green light shone upon plants is wasted, as it’s not used for photosynthesis. Green light is the exactoppositeof grow light.

author: wizard69
author_rank: Super Contributor
timestamp: January 31, 2021, 09:49:19 pm
content: Quote from: DrG on January 22, 2021, 05:56:28 pmIf the transistor is functioning as a switch then yes it is better to operate it in saturation mode. As for what is happening in your schematics it would be best to analyze the circuits to see if saturation is achieved. Honestly it has been a long time and I would have to get out a handbook to do so right. In either case you need to make sure your base current is proper for the transistor being used and of course that your don't source more current from the microcontroller than you should.

author: Zero999
author_rank: Super Contributor
timestamp: January 31, 2021, 10:17:37 pm
content: Quote from: tooki on January 31, 2021, 07:57:07 pmI was not disputing what you said, merely adding more information.QuoteThat's what I used to think, until I noticed some green LEDs designed for use in grown lamps and it turns out that green light does have some benefits to plant growth.https://gpnmag.com/article/growing-plants-with-green-light/

author: tooki
author_rank: Super Contributor
timestamp: January 31, 2021, 11:53:00 pm
content: Quote from: Zero999 on January 31, 2021, 10:17:37 pmI have definitely heard of full-spectrum grow lights that include green and IR (and generally, other wavelengths in between the red and blue peaks), and that that is beneficial. But just green?!? I looked, and it seems those are sold as "dark cycle" bulbs so that humans can navigate the greenhouses without "waking up" the plants so to speak.

author: DrG
author_rank: Super Contributor
timestamp: February 01, 2021, 12:32:58 am
content: Quote from: wizard69 on January 31, 2021, 09:49:19 pmSo, when I said "switch", I meant it in a very simple way - turn the LED on/off. If you read the the explanation for the "Q2" circuit, he explicitly says:...The first thing to note is that the transistor can't saturate in this circuit. Since the base is driven to at most 3.3 V, the emitter is never more than 2.6 V due to the 700 mV B-E drop. That means there is always a minimum of 700 mV accross C-E, which is well above the 200 mV saturation level...https://electronics.stackexchange.com/questions/60865/how-to-drive-a-20ma-led-from-a-4ma-max-gpio-pin(the point was also noted in this thread).That is why I was, initially, reluctant to use it (my level of experience is with using a transistor as a switch in saturated mode and why I posted the question. As I mentioned, I feel more comfortable (but not "kick back and a have a beer" comfortable) with the emitter follower configuration now, at least with regard to how I am using it in the project.

author: Zero999
author_rank: Super Contributor
timestamp: February 01, 2021, 01:41:03 pm
content: Quote from: tooki on January 31, 2021, 11:53:00 pmThat's an interesting application, but I would thought a very narrow band light source would be required for that to work well. The LED I was using certainly wouldn't be suitable for keeping the plants dormant. It was a broadband yellowish-green emitter, with the data sheet stating a better PPF for the lime green, than cold white LEDs.https://docs.rs-online.com/21af/0900766b8152e85f.pdfQuote from: DrG on February 01, 2021, 12:32:58 amThe emitter follower is no better, nor worse, than the common collector configuration. It depends on the application. If it's driving an LED, with a resistor and there's sufficient voltage headroom, it makes little difference, since the extra voltage has to be dissipated as heat, at some point. The advantage of the emitter follower is speed. Add a diode (anode to the LED's anode and cathode to collector) to speed up the turn-off time, by providing a path to discharge the LED's parasitic capacitance into the MCU IO pin.

author: David Hess
author_rank: Super Contributor
timestamp: February 11, 2021, 02:12:07 am
content: Quote from: DrG on January 22, 2021, 05:56:28 pmThere is no disadvantage other than the additional loss of one Vbe or about 0.6 volts.In the past when TTL (transistor transistor logic) was common the second circuit would have problems because of a poorly defined output high level and poor output high drive. This could be solved by using a pull-up resistor but this adds another part and increases current draw. In the past I often got around this by using a PNP transistor to pull the LED down which works just as well then and now but the application might require the LED to be illuminated with a high instead of low level.