4
\$\begingroup\$

I've got a microcontroller with a 3.3 V tolerant digital pin that I would like to use to drive this device. I want the LED to connect to a 5 V regulator. I'm just a bit unsure of how to drive it. Is the best way to do this to use an NPN transistor?

\$\endgroup\$
5
  • 2
    \$\begingroup\$ What's the LED operating voltage and current? Does the LED or other components have actual part numbers and datasheets, or is this a generic question? \$\endgroup\$
    – Justme
    Aug 14, 2022 at 22:48
  • \$\begingroup\$ 3.2V forward voltage. 20mA forward current. 5V supply voltage. \$\endgroup\$
    – ardoknow
    Aug 14, 2022 at 22:55
  • \$\begingroup\$ Is this just an indicator or is the LED intended to provide illumination? For indicator purposes in normal room lighting only a couple of mA is usually required for good brightness. The 20mA you state is probably the maximum current. \$\endgroup\$ Aug 15, 2022 at 0:08
  • \$\begingroup\$ Yes you’re right I’ve given the maximum. I sized the resistor for a 10mA max. They’re just indicators. \$\endgroup\$
    – ardoknow
    Aug 15, 2022 at 0:14
  • \$\begingroup\$ Maybe try to drive your LED directly from your controller pin with a small resistor like 100R. In most cases it will be bright enough, if you need just an indicator LED, \$\endgroup\$
    – Mike
    Aug 15, 2022 at 5:17

4 Answers 4

8
\$\begingroup\$

Or you could use a MOSFET with a VGS threshold under 3.3 V (like a 2N7000). But NPN will work. If you use a MOSFET, make sure to add a series resistor of a hundred ohms to limit the current on the gate.

\$\endgroup\$
18
  • 2
    \$\begingroup\$ Thanks. So for the NPN, would something like a 2N2222 do? \$\endgroup\$
    – ardoknow
    Aug 14, 2022 at 23:01
  • 4
    \$\begingroup\$ @MissMulan Vgs only has infinite resistance at DC so your advice does not apply. The gate is a highly capacitive load so it only makes sense to use a resistor in series when driving a FET gate to protect the MCU IO pin, to limit a high current spike every time the pin state changes. \$\endgroup\$
    – Justme
    Aug 14, 2022 at 23:48
  • 2
    \$\begingroup\$ @MissMulan Gate is driven on and off with an edge going high or low. Capacitance is zero impedance to an edge. To approach from frequency perspective, an edge has frequencies up to infinity, so it contains unreasonable frequencies. \$\endgroup\$
    – Justme
    Aug 15, 2022 at 0:02
  • 4
    \$\begingroup\$ @MissMulan That is true, but if you don't look at the frequency perspective, you are still charging and discharging a capacitance with a step waveform, and with no resistor, the IO pin driver impedance is the only current limit. IO pins are not meant to directly drive large capacitive loads such as FET gates. \$\endgroup\$
    – Justme
    Aug 15, 2022 at 0:26
  • 5
    \$\begingroup\$ @MissMulan To push the required 1 nanocoulombs in 10 ps into 2N7000 FET gate, you need 100 amperes for the whole 10 picoseconds. The MCU pin can't provide 100 amperes, so the transient response will last quite a bit longer than a few ps. So the series resistor is beneficial to limit current to safe levels. A typical 3.3V MCU could maybe drive a 50pF load in 8ns, resulting into about 20mA drive ability, with absolute maximum pin current that must not be exceeded around 25mA. A large FET can easily have 1000 to 2000 pF of gate capacitance. \$\endgroup\$
    – Justme
    Aug 15, 2022 at 1:00
6
\$\begingroup\$

You seem to already know the basic NPN circuit and just want to know how to calculate the resistor values.

A transistor in saturation will have 0.6-0.7 V on its base and the collector will be 0.1-0.2 V.

If you truly want 20 mA through the LED and that drops 3.2 V, then the voltage across the collector resistor will end up being about 1.6 V as shown below.

enter image description here

Rc = V/I = 1.6/.02 = 80 ohms

If we assume a min transistor beta of 50, then the base current will be .02/50 = 0.4 mA

Rb = V/I = 2.6/.0004 = 6.5k

In reality you’ll probably only need 5-10 mA for the LED. The 80 ohms serves as an absolute minimum, just make it bigger until brightness is still acceptable.

For the base resistor don’t blindly trust beta values – error on the small side. Better to make sure transistor is well saturated than to drive it too wimpily.

You don’t need or want an additional resistor from base to VCC.

\$\endgroup\$
3
  • \$\begingroup\$ Perfect. Thank you for this, it really helps me understand everything that's going on. By "well saturated" do you mean don't raise the resistor value too high? \$\endgroup\$
    – ardoknow
    Aug 15, 2022 at 7:56
  • \$\begingroup\$ @ardoknow Yes. Rb should not be high. A transistor allows a certain collector current given a specific base current. This relation is coarsly proportional, and the between base current and the maximum collector current it allows factor is called amplification factor, hFE or beta. If you limit the collector current by external means (Rc in this case), more base current than strictly required doesn't matter. We call a situation where the base current is high enough that Vce is around 0.2V (the typical minimum) "saturated". "Well satured" means even more base current, just to be sure. \$\endgroup\$ Aug 15, 2022 at 8:58
  • \$\begingroup\$ Formally, there should also be a pull-down resistor from the base to ground. But the device you are driving this from may already have that built in \$\endgroup\$
    – keshlam
    Aug 15, 2022 at 13:42
4
\$\begingroup\$

You could make a simple capacitive boost circuit that can provide enough voltage to drive the LED directly from the MCU. This example shows a 25 kHz 3 V square wave with 4.4 mA into the LED at 3.1 V. The MCU output is given to have an internal resistance of 100 ohms corresponding to a short circuit current of 30 mA. It will have an initial surge of about 28 mA and subsequent peak current will be about 17 mA. The component values are non-critical and may be adjusted as desired.

Capacitive Boost Circuit 3V

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, I may try this on another board. Are there other uses for such a circuit apart from driving an LED? \$\endgroup\$
    – ardoknow
    Aug 15, 2022 at 7:57
  • 1
    \$\begingroup\$ This circuit is simple and cheap if you already have the possibility to get a square wave. This circuit is neither precise, nor very efficient, nor optimzed for low noise. A circuit like that is useful if you need a low power source of voltage exceeding the supply voltage if the drawbacks don't matter. With a slight variation, it can also be used to create a voltage more negative than GND. \$\endgroup\$ Aug 15, 2022 at 9:03
1
\$\begingroup\$

If only 4-5 mA LED current are needed and a LED with above 3 V forward voltage is used, it can be done this way:

schematic

simulate this circuit – Schematic created using CircuitLab

  1. When the main supply voltage rises, the 3.3 V output of the linear regulator rises as well but is lagging behind some ms.
  2. The worst case is, if 5 V is already reached and the 3.3V line is still 0 V. If the LED forward voltage is 3 V we have a V_DNEG of 2 V.
  3. The protection diode in the MCU output has a forward voltage of 0.5 V, so we have 1.5 V across R1.
  4. The current flow into the MCU output will be 3.85 mA peak and falling as the 3.3 V line rises. This is acceptable for many MCUs, at least as a transient condition, but not for all!
  5. If the MCU is powered up and the output is low, we have a LED current of about 4-5 mA, if the output is high, we have no LED current except some leakage.
\$\endgroup\$

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.