Component values question for simple LED path. - Page 1
Forum section: electronics / beginners

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 29, 2022, 01:52:18 am
content: 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?

author: sleemanj
author_rank: Super Contributor
timestamp: November 29, 2022, 02:04:49 am
content: 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.

author: WattsThat
author_rank: Frequent Contributor
timestamp: November 29, 2022, 02:20:14 am
content: 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.pdfFor 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.

author: MikeK
author_rank: Super Contributor
timestamp: November 29, 2022, 02:29:12 am
content: See Figure 5 in this datasheet:https://rocelec.widen.net/view/pdf/orqxwkxkq1/ONSM-S-A0003544006-1.pdfYou *might* be able to get 50mA with only 3.3Vgs, but it's going to be close.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 29, 2022, 03:08:35 am
content: 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.

author: james_s
author_rank: Super Contributor
timestamp: November 29, 2022, 03:18:47 am
content: 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.

author: MikeK
author_rank: Super Contributor
timestamp: November 29, 2022, 03:36:48 am
content: Quote from: msuffidy on November 29, 2022, 03:08:35 amThis 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.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 02:51:32 am
content: 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.

author: james_s
author_rank: Super Contributor
timestamp: November 30, 2022, 03:11:36 am
content: 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.

author: james_s
author_rank: Super Contributor
timestamp: November 30, 2022, 03:14:27 am
content: Here are some resources you can check out;https://www.baldengineer.com/low-side-vs-high-side-transistor-switch.htmlhttps://learn.sparkfun.com/tutorials/transistors/applications-i-switchesAnd 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/

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 03:29:20 am
content: 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.

author: james_s
author_rank: Super Contributor
timestamp: November 30, 2022, 03:35:03 am
content: 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.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 04:04:07 am
content: 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.

author: james_s
author_rank: Super Contributor
timestamp: November 30, 2022, 04:07:51 am
content: 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.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 04:16:35 am
content: 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.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 04:18:12 am
content: My iPhone 5C in front camera mode can see IR if that was confusing.

author: james_s
author_rank: Super Contributor
timestamp: November 30, 2022, 04:24:57 am
content: 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.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 04:31:20 am
content: I put a 2.2K resistor for the base and it is working again.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 04:32:25 am
content: Maybe I'll try a 1K because the range seems shorter. It may be a partial switch on.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 04:33:18 am
content: No its ok maybe something was blocking it. Seems fine. 11 foot control range. Maybe gnd was usb and not regulator (gnd)?

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 05:04:01 am
content: Here is the updated stuff:

author: MikeK
author_rank: Super Contributor
timestamp: November 30, 2022, 02:03:46 pm
content: 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.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 30, 2022, 03:49:57 pm
content: 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:

author: james_s
author_rank: Super Contributor
timestamp: November 30, 2022, 05:50:39 pm
content: 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.

author: Terry Bites
author_rank: Super Contributor
timestamp: December 03, 2022, 08:51:58 am
content: Just so. For practical purposes assume that 200mV is dropped across CE. AKA VcesatR =(Vrail-VLED-Vcesat)/iYou 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!

author: tooki
author_rank: Super Contributor
timestamp: December 03, 2022, 01:16:41 pm
content: Quote from: msuffidy on November 29, 2022, 01:52:18 amQuick question, is that an IR LED for sending remote control commands? If so, you need to know that 50mA is way too little. Typical IR remote emitters are designed to be pulsed at 1-1.5A. The only reason they don’t burn up instantly is because of the low duty cycle. But those high currents is how you get decent range.

author: wasedadoc
author_rank: Super Contributor
timestamp: December 03, 2022, 03:26:42 pm
content: Quote from: msuffidy on November 29, 2022, 03:08:35 amFor future reference, a BJT does not have a gate, so mentioning "gate resistor" is incorrect.

author: msuffidy
author_rank: Frequent Contributor
timestamp: December 04, 2022, 06:29:30 am
content: Quote from: tooki on December 03, 2022, 01:16:41 pmI was expecting 300ma, but I have no data on this specific IR led I harvested out of a cheap LED strip remote, so I played it safe at 50ma. Most remotes I have used have a range of about 25 feet. This one is about 10 which is not as good but not bad.

author: RJSV
author_rank: Super Contributor
timestamp: December 04, 2022, 09:17:40 pm
content: You've moved that LED back to being above the bjt, but by way of explanation, why; the reason LED on emitter is not so good is that your driver to the bjt base would then have to 'overcome' the LED voltage.That is, the usual nominal 0.7 V when driving transistor has to have the LED drop added...so, if LED is, say 2.2V then that's 2.9 volts that your processor output needs to be. That's marginal, but worse for the IR type, as the voltage requirement for the processor starts approaching RAIL or the max possible.When put on the collector, most designers don't even deal, much with the 'Vsat.' at nominal '002'...just assume LED connects to ground.I think maybe high power circuits, like for driving audio speakers at high power (30 watts etc), those start needing consideration, the Vsat. on power output circuit transistors.2n2222 is also a nice NPN for LEDs.