Author Topic: Component values question for simple LED path.  (Read 2673 times)

0 Members and 3 Guests are viewing this topic.

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Component values question for simple LED path.
« on: November 29, 2022, 01:52:18 am »
I have read the maximum current draw for an ESP8266 GPIO is 15ma. They are at 3.3V. So if you want a IR led with say a 50ma draw, you have to use a different sort of setup than a resistor and a LED. So in this diagram The path between the USB 5V and ground is being turned off and on with a FET. So my question is, what is the voltage drop across a FET that together can be used to determine the value of the resistor? Also can I assume in this diagram, that at the point of the transistor the voltage across the FET is basically the forward drop, as the resistor would lower the voltage from the LED to the FET to ground? In this case a 3.3V line would control a FET with like a 0.8 volt drop?
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3047
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Component values question for simple LED path.
« Reply #1 on: November 29, 2022, 02:04:49 am »
When in the ON state, the Mosfet has a resistance Rds(on), which you can find (an approximation of) in the datasheet.

For your purposes, you can ignore it as it's going to be negligible compared to your main resistor.

The voltage across the mosfet in in the ON state will be in accordance with Ohm's law as applied to the current through, and Rds(on) of the fet.

~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline WattsThat

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: us
Re: Component values question for simple LED path.
« Reply #2 on: November 29, 2022, 02:20:14 am »
Beware, the 2N7002 is a really bad choice for 3.3 volt gate drive levels as the channel is not fully formed until the gate has about 4 volts applied. Lots of far better parts out there but they’re all SMD which is why the 2N7002 gets used - as it is a through hole part which is it’s only good attribute. Have a look at figure 7 in the datasheet here:

https://assets.nexperia.com/documents/data-sheet/2N7002.pdf

For a low current applications, it may appear to work but it’s a crap shoot, especially with eBay or Amazon sourced parts. For what you’re doing, a bipolar transistor would be fine, the only down side is that it would need a base resistor.
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1316
  • Country: us
Re: Component values question for simple LED path.
« Reply #3 on: November 29, 2022, 02:29:12 am »
See Figure 5 in this datasheet:

https://rocelec.widen.net/view/pdf/orqxwkxkq1/ONSM-S-A0003544006-1.pdf

You *might* be able to get 50mA with only 3.3Vgs, but it's going to be close.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #4 on: November 29, 2022, 03:08:35 am »
Thanks maybe I'll go BJT with the gate resistor. Still don't know exactly how to enter the bjt transistor into the main resistor calculations. I am assuming the bjt gate resistor should be calculated as to produce like 10ma.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Component values question for simple LED path.
« Reply #5 on: November 29, 2022, 03:18:47 am »
I would use a BJT such as the common 2N3904. In that case you can assume a forward drop of around 0.2V for saturation (fully turned on) and just subtract that from the supply voltage in your calculations.
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1316
  • Country: us
Re: Component values question for simple LED path.
« Reply #6 on: November 29, 2022, 03:36:48 am »
Thanks maybe I'll go BJT with the gate resistor. Still don't know exactly how to enter the bjt transistor into the main resistor calculations. I am assuming the bjt gate resistor should be calculated as to produce like 10ma.

This is a situation where the BJT is being used as a switch, not a small signal amplifier.  Use the saturated gain in the datasheet, which I think, is 10 for 2N3904?...Look for "Vce(sat)" and look at the two currents.  So use a base resistor (and base-emitter drop of 0.65V-ish) to produce 5mA of base current.  Then size your collector resistor to produce your 50mA.

FWIW, Applied Science on YouTube has a good video on using a BJT as a switch.  Also on YT is W2AEW's videos on using BJT's.  There may be other good videos, but two guys are good.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #7 on: November 30, 2022, 02:51:32 am »
OK I thought I'd try it out to see if I could get it working. I have some parts around here and found a C1740 NPN transistor. It had a strange pinout but I trusted it and took a big gulp. I am a little unclear about how the base voltage works. In this case it is 3.3 volts, which is less than 5 volts, which is how transistors are supposed to work. The IR control is working properly. Originally I wanted to use the GPIO the onboard led was on, but the IR led seemed to be on all the time, so I moved the lead to GPIO0 and it worked as expected. Initially I thought there was a catastrophic wiring issue. Here are my calculations etc. I planned it like there was going to be a 0.7 volt drop across the base which I don't know exists or not. Not a big deal. I shot for 8ma for the base, and 50ma for the LED. The LED has a range of about 6 feet. Oops maybe I forgot to add the IR drop in the base resistor, think it is in safety favor though.
« Last Edit: November 30, 2022, 03:01:00 am by msuffidy »
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Component values question for simple LED path.
« Reply #8 on: November 30, 2022, 03:11:36 am »
You've got that wired up wrong, it may work but not very well. Tie the emitter of the NPN directly to ground, put the LED above it connected between your supply and the collector. The arrangement is called a low side switch.

It's best to think of base *current* rather than base voltage with a BJT, they are current driven rather than voltage driven as mosfets are. The B-E junction acts like a diode, so it has a forward drop of about 0.6V. Since your emitter is (supposed to be) connected directly to ground, you can treat that junction just like an LED when calculating the resistor. Look on the datasheet what the saturation current is and calculate for about that value, take your supply voltage, subtract 0.6V and then plug the resulting voltage and desired current into Ohms law and see what you get. Wild assed guess going from memory is 1k will probably work fine.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Component values question for simple LED path.
« Reply #9 on: November 30, 2022, 03:14:27 am »
Here are some resources you can check out;

https://www.baldengineer.com/low-side-vs-high-side-transistor-switch.html
https://learn.sparkfun.com/tutorials/transistors/applications-i-switches

And here's a simple but effective simulator you can use to play around with different component values with no risk of damaging anything. Just for fun you can even crank the voltage up to megavolts.
https://www.falstad.com/circuit/
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #10 on: November 30, 2022, 03:29:20 am »
Oh the LED is supposed to go above the transistor. Does it matter? Oh ok maybe the problem is that voltage is best to be lower at the point of bias, and it is higher in this example.
« Last Edit: November 30, 2022, 03:38:33 am by msuffidy »
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Component values question for simple LED path.
« Reply #11 on: November 30, 2022, 03:35:03 am »
It's hard to follow a picture of a breadboard, especially when the wires are all the same color, but the schematic that you attached is wired wrong.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #12 on: November 30, 2022, 04:04:07 am »
 OK I changed it and the LED is on all the time now so my theory is the base resistor value is too low and its low state is enough to bias the transistor. I will try a larger resistor.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Component values question for simple LED path.
« Reply #13 on: November 30, 2022, 04:07:51 am »
That shouldn't matter, the low state should be close enough to 0V that even with no resistor the transistor should stay off. Double check the connections, and check that the transistor is ok. With nothing connected to the base,  E connected to ground and C connected to the cathode of the LED the LED should be off.
 
The following users thanked this post: 807

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #14 on: November 30, 2022, 04:16:35 am »
I tried a little experiment. I disconnected GPIO0 and the LED went off. That is the one going into the 360 ohm resistor and then into the base. I reconnect it and it turns back on. It is supposed to be in a low state and I think it is. I totally understand your concern.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #15 on: November 30, 2022, 04:18:12 am »
My iPhone 5C in front camera mode can see IR if that was confusing.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Component values question for simple LED path.
« Reply #16 on: November 30, 2022, 04:24:57 am »
Do you have an oscilloscope? Or even a multimeter? Check the voltage of the GPIO pin. It should be within a few mV of 0V when low and around 3.3V when high.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #17 on: November 30, 2022, 04:31:20 am »
I put a 2.2K resistor for the base and it is working again.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #18 on: November 30, 2022, 04:32:25 am »
Maybe I'll try a 1K because the range seems shorter. It may be a partial switch on.
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #19 on: November 30, 2022, 04:33:18 am »
No its ok maybe something was blocking it. Seems fine. 11 foot control range. Maybe gnd was usb and not regulator (gnd)?
« Last Edit: November 30, 2022, 04:49:16 am by msuffidy »
 

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #20 on: November 30, 2022, 05:04:01 am »
Here is the updated stuff:
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1316
  • Country: us
Re: Component values question for simple LED path.
« Reply #21 on: November 30, 2022, 02:03:46 pm »
Do the calculation.  A 2.2k base resistor is going to create about 1mA of base current.  And 1mA of base current is only going to be able to switch 10mA of collector current.  Far short of your desired 50mA.  Put the correct base resistor back in.  If the LED is staying on then you've either wired it incorrectly or your ESP32 code is wrong or your ESP32 is faulty.  Check the GPIO pin voltage when the output is not switched on.  It should be 0V.  You could put a 10K pulldown resistor at the base to ground to make sure GPIO leakage current isn't switching on the transistor, but it should not be necessary.  That GPIO pin should be 0V when not switched on.
 
The following users thanked this post: 807

Offline msuffidyTopic starter

  • Regular Contributor
  • *
  • Posts: 247
  • Country: ca
Re: Component values question for simple LED path.
« Reply #22 on: November 30, 2022, 03:49:57 pm »
I was worried about that but I think the datasheet mentions gains above 100 times, so I think that is still within 50ma. The datasheet and others for this part seem to mention that the base is the pin on the edge which is different from most transistors. The code is fine, it controls IR receivers. You can see it working near the end of this:

« Last Edit: November 30, 2022, 03:55:19 pm by msuffidy »
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Component values question for simple LED path.
« Reply #23 on: November 30, 2022, 05:50:39 pm »
You still haven't looked at the GPIO pin with a scope or meter as far as I can tell, that would tell you a lot about what's going on. Many of the IO pins on those ESP devices are shared between multiple functions, at least one of them typically connects to an onboard LED, not all of them behave the same way. The LED should never come on when the IO pin is low, no matter what value base resistor you use.
 
The following users thanked this post: 807

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 2523
  • Country: gb
  • Recovering Electrical Engineer
Re: Component values question for simple LED path.
« Reply #24 on: December 03, 2022, 08:51:58 am »
Just so. For practical purposes assume that 200mV is dropped across CE. AKA Vcesat

R =(Vrail-VLED-Vcesat)/i   

You might see circuits with a volage divder on the base. Unless swiching speed is an issue, you only need a single transistor.
Look at the DC current gain or Hfe. For a small signal transistor this is typically 100 so the minimum base current is iLed/100.
The driving voltage is Voh , the transistor vbe is say 0.7V. Go figure.
I've never calculated this, I just choose Rbase =RLed*50. Never let me down yet!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf