Electronic – Driving an LED from a uC pin with the Anode above uC’s Vcc rail

avrledmicrocontroller

I am using a 3.3V uC (ATMega 328p in Arduino Pro Mini) running from 3 alkalines (nominal 4.5V). So Vin=4.5V, Vcc=3.3V

I'd like to drive LEDs from some pins, say at 20ma each. And I was thinking to connect the LED anodes to Vin (4.5v) with the cathode going to the uC pin, rather than putting all the LED currents through the 3.3v onboard regulator. (Also, while I'll use Red LEDs in the example here, I may want to use Blue as well, which would be more comfortable with a bit more driving voltage).

I figure a red LED at about 2v Vfwd, so the resistor would need to drop 2.5v @ 20ma, say 1K2 ohms.

The issue: this connect a uC pin to a source 1.2V about its Vcc rail (through an LED).

I think we are fine when the LED is on (pin low). But what about turning the LED off?

schematic

simulate this circuit – Schematic created using CircuitLab

Approach 1: Pull uC pin high (3.3v) to turn off the LED. The LED is between 4.5V and 3.3V, and the 1.2v difference will not be enough to light it – and I THINK it also won't bring the pin too high above its rail. But LEDs are not ideal devices, hence this question.

Approach 2: tristate uC pin (make it an input) to turn off the LED. The LED is between 4.5V and the high impedance input (along with it's static protection diode to Vcc). Again, I hope the LED's Vfwd would be enough protection for the uC pin.

Is either or both of these approaches workable and safe for the uC?

EDIT: substitute 120 ohm resistor above, oops.

Best Answer

What you're talking about is not huge risk for a hobby project.. a few things to think about.

It's not really the \$V_F\$ at the operating current that matters, it's the \$V_F\$ at the maximum 'off' brightness that is acceptable. That voltage might be as low as 1.4-1.5V volt for a low-current red LED- in a dark room they can be quite visible with microamperes of current. Driving the output to the 3.3V (nominal level) gets us 3.3V on the output. A fresh alkaline cell with minimal load might be 1.63V/cell at room temperature (just measured one), so 3 would be 4.89V. That leaves you with 1.59V across the LED + resistor (nominal, not allowing that the 3.3V might be a few percent low).

That's way too much to ensure it's not emitting a whole bunch of light.

So, we tri-state it- that allows the output to go maybe a bit above Vcc without much current flowing. 300mV is safe, the datasheet says 500mV absolute maximum. At 500mV, we'd have 1.09V across the LED, probably enough to ensure it's off, at least under nominal conditions. The 'absolute maximum' figure is never a good thing to design to, but usually there's a caveat on this particular figure that allows that voltage or a bit more if the current is limited.

So, I do think this will work (with tri-state, not push-pull), and I also think it's acceptable enough for a hobby project assuming nobody is going to be using a battery eliminator on the circuit in the future*. Keep in mind the margin on the red LEDs is minimal and consider eschewing red in favor of yellow or orange. Or, simply add a silicon diode in series with the red LEDs (one diode can be used for several LEDs).

  • If the ESD protection network in the ATMEGA328P does begin to conduct it will tend to raise up the 3.3V supply, out of control of the regulator. This is not a good thing for stability and could conceivably damage something, though the ATMEGA328P-M itself is rated for 5V operation.

I once did something like this in a commercial product (to drive a series string of LEDs with high Vf using a 5V constant-current output), but I designed a power supply with just the correct oddball voltage and appropriate temperature coefficient to match the LEDs and thus optimize the situation. I think the supply was around 8-9V. Worked a treat, easily from -20°C to 80°C (spec was 0-50°C).