Author Topic: NPN with no base resistor to drive an LED from a GPIO  (Read 4766 times)

0 Members and 1 Guest are viewing this topic.

Offline DrGTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
NPN with no base resistor to drive an LED from a GPIO
« on: January 22, 2021, 05:56:28 pm »
I have a project in which I need the microcontroller to flash an LED as an alarm. This is the LED https://www.nteinc.com/specs/30000to30099/pdf/nte30030_36_44.pdf high brightness but nothing special. Edit: The one I am using is NTE30034 Red Ic max 25mA Vf max 2.5V

Within 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 design https://electronics.stackexchange.com/questions/60865/how-to-drive-a-20ma-led-from-a-4ma-max-gpio-pin and, 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?

« Last Edit: January 22, 2021, 06:08:37 pm by DrG »
- Invest in science - it pays big dividends. -
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22022
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #1 on: January 22, 2021, 06:01:06 pm »
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline DrGTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #2 on: January 22, 2021, 06:10:25 pm »
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

Thanks. Yes, it is red.
- Invest in science - it pays big dividends. -
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2095
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #3 on: January 22, 2021, 06:35:15 pm »
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.
« Last Edit: January 22, 2021, 06:40:21 pm by Peabody »
 

Offline S. Petrukhin

  • Super Contributor
  • ***
  • Posts: 1270
  • Country: ru
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #4 on: January 23, 2021, 12:29:00 am »
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.
And sorry for my English.
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 515
  • Country: au
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #5 on: January 23, 2021, 09:39:33 am »
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).
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12986
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #6 on: January 23, 2021, 09:53:55 am »
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.   
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19687
  • Country: gb
  • 0999
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #7 on: January 23, 2021, 10:09:39 am »
Nothing wrong with the Q2 circuit. If anything it should work better, Q2 will saturate quickly as soon as the LED conducts.
Q2 will not saturate, because it's an emitter follower.
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 515
  • Country: au
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #8 on: January 23, 2021, 10:55:49 am »
Nothing wrong with the Q2 circuit. If anything it should work better, Q2 will saturate quickly as soon as the LED conducts.
Q2 will not saturate, because it's an emitter follower.
Yes 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.
 

Offline wolframore

  • Newbie
  • Posts: 5
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #9 on: January 23, 2021, 04:44:26 pm »
What a clever circuit  :-+

Keep 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.
« Last Edit: January 23, 2021, 04:48:14 pm by wolframore »
e^jpi +1 = 0
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12047
  • Country: ch
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #10 on: January 23, 2021, 04:59:28 pm »
It better be a red LED.
Or 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.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22022
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #11 on: January 23, 2021, 05:17:49 pm »
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline DrGTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #12 on: January 23, 2021, 06:10:13 pm »
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 example https://www.aliexpress.com/item/4000241319430.html



I 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-40v and 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?
« Last Edit: January 23, 2021, 06:52:31 pm by DrG »
- Invest in science - it pays big dividends. -
 
The following users thanked this post: tooki

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22022
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #13 on: January 23, 2021, 06:34:38 pm »
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.pdf

Tim
« Last Edit: January 23, 2021, 06:36:15 pm by T3sl4co1l »
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: DrG

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19687
  • Country: gb
  • 0999
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #14 on: January 23, 2021, 06:51:21 pm »
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.
 

Offline DrGTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #15 on: January 23, 2021, 06:56:19 pm »
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.

Hmmm I can see the piezo element through the hole - no?
- Invest in science - it pays big dividends. -
 

Offline rsjsouza

  • Super Contributor
  • ***
  • Posts: 6025
  • Country: us
  • Eternally curious
    • Vbe - vídeo blog eletrônico
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #16 on: January 23, 2021, 07:04:33 pm »
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.
Vbe - vídeo blog eletrônico http://videos.vbeletronico.com

Oh, the "whys" of the datasheets... The information is there not to be an axiomatic truth, but instead each speck of data must be slowly inhaled while carefully performing a deep search inside oneself to find the true metaphysical sense...
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19687
  • Country: gb
  • 0999
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #17 on: January 23, 2021, 07:14:12 pm »
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.

Hmmm I can see the piezo element through the hole - no?
Are 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.jpg
https://www.slideshare.net/emilycalvin/operating-principle-of-magnetic-transducer
https://www.cuidevices.com/blog/buzzer-basics-technologies-tones-and-driving-circuits
« Last Edit: January 23, 2021, 07:48:45 pm by Zero999 »
 

Online ledtester

  • Super Contributor
  • ***
  • Posts: 3119
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #18 on: January 23, 2021, 07:14:41 pm »
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.


 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19687
  • Country: gb
  • 0999
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #19 on: January 23, 2021, 07:22:49 pm »
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/
 

Offline DrGTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #20 on: January 23, 2021, 07:30:38 pm »
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.

Hmmm I can see the piezo element through the hole - no?
Are 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 steal 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.jpg
https://www.slideshare.net/emilycalvin/operating-principle-of-magnetic-transducer
https://www.cuidevices.com/blog/buzzer-basics-technologies-tones-and-driving-circuits

Well, 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.
« Last Edit: January 23, 2021, 07:34:05 pm by DrG »
- Invest in science - it pays big dividends. -
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12986
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #21 on: January 23, 2021, 07:38:42 pm »
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, 
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19687
  • Country: gb
  • 0999
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #22 on: January 23, 2021, 07:48:18 pm »
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.
 

Offline DrGTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #23 on: January 23, 2021, 07:54:15 pm »
I wonder if an android magnetometer app would work?
- Invest in science - it pays big dividends. -
 

Offline wraper

  • Supporter
  • ****
  • Posts: 17339
  • Country: lv
Re: NPN with no base resistor to drive an LED from a GPIO
« Reply #24 on: January 23, 2021, 07:59:21 pm »
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.

« Last Edit: January 23, 2021, 08:16:35 pm by wraper »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf