2
\$\begingroup\$

I have a project using an ESP8266 to control a lamp socket. In very simple terms the sketch switches the lamp socket on or off based on some conditions. The sketch works fine.

What I would like to be able to do is put into the lamp socket either a 3 V 120 mA incandescent bulb or a 3 V 1 mA LED bulb.

The ESP8266 can easily drive the LED directly but of course can't drive the incandescent bulb, so I added a 2N4401 transistor into the circuit with the ESP8266 controlling the base of the transistor.

The problem is that the base resistors required vary dramatically. My calculations indicate the incandescent requires 383 Ω while the LED requires 4.6K Ω. In practical testing, the incandescent requires 1 kΩ to completely shut it off (much less than that and the incandescent will slightly glow when the pin connected to the base is low--i.e., off) yet fully saturate the transistor--i.e., fully on.

Strangely, the LED will not shut off fully even with a 20 kΩ resistor while at this level of resistance on the base the incandescent barely lights.

Using a standard BJT NPN transistor is not going to do the trick. I was thinking maybe a Darlington transistor or MOSFET might be a better solution, but I have never worked with either (although I have done a bit of reading on both.)

enter image description here

\$\endgroup\$
25
  • 2
    \$\begingroup\$ Can you add a schematic of you setup? \$\endgroup\$
    – HandyHowie
    Commented Feb 21, 2022 at 14:45
  • 1
    \$\begingroup\$ Overly complex but possible would be to feed it 1 mA and check what voltage you get. Too low = switch to incandescent mode and bypass the current limiter. High enough = LED installed and everything is good. \$\endgroup\$
    – winny
    Commented Feb 21, 2022 at 14:45
  • 4
    \$\begingroup\$ What I'm getting from this is that you're trying to limit current by playing with the transistor's base current. That's not how it's done, transistor Hfe differs greatly between parts, temperature, etc... \$\endgroup\$ Commented Feb 21, 2022 at 14:49
  • 3
    \$\begingroup\$ Currently you are trying to feed the base of the BJT with just enough current to switch the thing you want to switch. You are free to supply the BJT with more base current than it strictly needs to let the collector-emitter current flow more freely. This avoids unnecessarily limitations. Just let the BJT switch fully and limit the current with an additional series resistor in case of the led. PS: they sell leds with built-in resistors to make it easier for the user that needs to swap these things out! \$\endgroup\$
    – Thijs
    Commented Feb 21, 2022 at 14:58
  • 2
    \$\begingroup\$ @DeanArnold You think you're using it as a switch, but you're not. See electronics.stackexchange.com/questions/402210/… That series resistor is what limits the lamp current so then the BJT base can be driven so it can be completely conducting without throttle. Then it's a switch. \$\endgroup\$
    – DKNguyen
    Commented Feb 21, 2022 at 14:59

3 Answers 3

1
\$\begingroup\$

Assuming your LED bulb is actually a bare LED which needs current limiting, here is one proposal for you.

This turned out really ugly, but here is a starting idea you can think about. If you don't have any more MCU pins, you can do a fully analog circuit which bypasses the current limiting resistor in case a bulb is installed instead of a LED by sensing the current, and triggering a latch circuit which in turn turns on a PFET in order to bypass the current limiting resistor.

PLENTY OF SIMPLIFICATIONS AND OPTIMIZATIONS IS POSSIBLE! V2 is your MCU output.

First off, LED installed. Current is too low to trigger. LED

A bulb installed instead. High current is sensed and latches on M2. Bulb

\$\endgroup\$
4
  • \$\begingroup\$ Thanks very much for taking the time to come up with a possible solution! Very interesting idea. LED Bulbs are not bare, rather they have a built-in current limiting resistor. \$\endgroup\$ Commented Feb 21, 2022 at 17:39
  • \$\begingroup\$ Gosh darn it! Then all you need is a MOSFET. All that simulation in vain. \$\endgroup\$
    – winny
    Commented Feb 21, 2022 at 17:44
  • \$\begingroup\$ I thought it might be worth a try. I just haven't really used/spec'd them before. I was looking at ordering some TN2106 Logic Level MOSFETs. Any other suggestions? \$\endgroup\$ Commented Feb 21, 2022 at 18:15
  • \$\begingroup\$ Should be as good as the next MOSFET… \$\endgroup\$
    – winny
    Commented Feb 21, 2022 at 18:22
0
\$\begingroup\$

TL;DR

BJT Rule #1: Use 5 to 10% of max hFE for a BJT switch. i.e. Ic/Ib = 20 to 10 : 1

Incandescent Rule #1: The lamp cold resistance is 5 to 10% of hot.

Thus 3 V / 120 mA = 25 ohms hot or 1.25 to 2.5 ohms cold. Thus R base needs to be 12.5 to 50 Ohms range.

Rule of CMOS Driver Impedance #1: Ro= Vol/Iol is in the above range so choose a compromise that matches that value of 12 Ohms and pull down with 1K to 0V to turn off an LED.

schematic

simulate this circuit – Schematic created using CircuitLab

Consider the 2N4401 like a 3 ohm switch and the PN2222A like a 1 ohm switch. Which one is better??

2N4401 Collector−Emitter Saturation Voltage (IC = 150 mAdc, IB = 15 mAdc) (IC = 500 mAdc, IB = 50 mAdc)
VCE(sat) = 0.4V max / 150 mA = Ro= 2.6 ohms with Ic/Ib=10

You can do the math for the '2222A which is better.

\$\endgroup\$
0
\$\begingroup\$

It is difficult to understand how you managed to calculate those values of base resistor, particularly 4.6 ohms which is way out.

The reason is that a transistor is a current amplifier; you put a current in the base, and get a larger current out of the collector. The ratio of these currents is the gain, but that is difficult to predict since it is dependant on various factors, including the temperature of the device.

Furthermore, the transistor clamps the maximum voltage between base and emitter at around 0.6V; force more in, and it will be destroyed. So putting 3.3V in, via a 4.6 ohm resistor, is asking for trouble; if you're lucky, the ESP8266 (like most logic ICs) will have a current-limit on its outputs, so the transistor and the ESP might have survived - but don't count on it.

So how to fix your circuit? Firstly, when you say 'LED bulb', I'm assuming this is a device with a built-in current-limiting resistor (or a similar electronic circuit). If this isn't true, you need to add an external resistor, for similar reasons to the transistor base; a LED is a constant-voltage device (around 2.1V for a red LED) and will be destroyed if you force a higher voltage in, so must be fed via a current-limiting device, normally a resistor.

You say the LED current is supposed to be 1 mA at 3V, but this does seem quite low for a bulb indicator (as opposed to a LED component); I would have expected 5 mA or more, unless this is a small point-source.

To drive the LED or incandescent bulb, you just need to saturate the transistor (turn it hard on) by feeding sufficient current into the base, such that you can guarantee it will be on, despite the variability of its gain. The main limit to this current is the ESP8266 I/O pins; you should really look this up, but I'd guess that a base resistor around 1K would do.

With regard to the strange results you are seeing when changing the base resistor, I do wonder whether you are actually dealing with a melted lump of silicon, rather than a real transistor, due to your over-enthusiasm in driving the base.

\$\endgroup\$
2
  • \$\begingroup\$ My mistake...I meant to type 4.6KΩ resistor...I have corrected it. \$\endgroup\$ Commented Feb 21, 2022 at 17:25
  • \$\begingroup\$ The LEDs bulbs I plan to use have a built-in current limiting resistor [link]amazon.com/dp/…. As mentioned in the comments, the 1K resistor works for the incandescent bulbs but does not fully turn-off the LED bulbs. Thank you for your concern but no I am not dealing with melted lumps of silicon. \$\endgroup\$ Commented Feb 21, 2022 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.