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?
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.
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.
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.
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.
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:
- When the main supply voltage rises, the 3.3 V output of the linear regulator rises as well but is lagging behind some ms.
- 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.
- The protection diode in the MCU output has a forward voltage of 0.5 V, so we have 1.5 V across R1.
- 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!
- 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.