Driving a LED with an open drain digital input

So I was thinking putting a classid circuit with a BJT. But then I saw that GPIO output of the microcontroller are configurables in open drain. So would this circuit work?

enter image description here

The LED has a 20mA forward current and 2V forward voltage so if R=(3.3-2)/0.02 it should be on if GPIO is HIghZ and off if it is GND no?

I don't see why this circuit would not work but I never saw it before so I just want to be before designing it.

edit: Then you mean it is better to do this:

enter image description here

edit2: Finally here is the schema I'll be using (my input GPIO is 3.3V and LED6FAIL is a push pull):

enter image description here


This circuit will work, but not be efficient, power-wise. If the output is high the LED is on and you'll have 20 mA current through LED and resistor.

But with the output low, the LED is short-circuited and therefore off, but the resistor current will be even higher: 50 mA!, which is not only bad for your wallet and the environment, but also for the output pin; most I/Os will only allow 25 mA.

Place the LED in series with the resistor. Then a high output won't light the LED because the output FET is switched off. A low output will draw the 20 mA through LED, resistor and open-drain output.

Note that this will invert the logic: in your first schematic the LED will be off when the output is active, in the second circuit it will be on with active output.

If the output can't sink enough current you'll need an external transistor to increase that.

enter image description here

If the output is active (low) there will flow a 1.5 mA from +3.3 V through Q2's emitter-base junction, R2 and Q1. That 1.5 mA will allow Q2 to source more than 100 mA for a typical general-purpose transistor. You will only get about 22 mA, though, because R1 won't allow more.

If Q1 is off there won't be any base current through Q1, so the LED will remain off. Q1 will have a small leakage current, and to avoid that this would get amplified by Q2 I added R3. As long as the leakage current is less than 0.7 V / 15 kΩ = 50 µA all the leakage current will flow through R3, so that will ensure Q2 will be completely off.