I need to drive an LED from an STM32F217ZG.

So I was thinking about a classic circuit with a BJT. But then I saw that GPIO outputs of the microcontroller are configurable as open drain. Would this circuit work?

enter image description here

The LED has a 20mA forward current and a 2V forward voltage. Considering \$R=(3.3-2)/0.02\$ it should be on, if GPIO is Hi-Z and off, if it is GND, right?

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

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

enter image description here

Edit 2: Finally here is the schematic I'll be using (the output GPIO LED6FAIL is 3.3V and it's a push-pull):

enter image description here

  • \$\begingroup\$ Regarding your 2nd edit, if the LED6_FAIL pin is open-drain, that circuit won't work. You should use steven's circuit. \$\endgroup\$
    – m.Alin
    Oct 18, 2012 at 12:43
  • \$\begingroup\$ @m.Alin - damien said in a comment to my answer that he would use a "regular" push-pull configuration instead of the open-drain. \$\endgroup\$
    – stevenvh
    Oct 18, 2012 at 12:47

1 Answer 1


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.

  • \$\begingroup\$ Thank you I edited my answer is it what you meant? \$\endgroup\$
    – damien
    Oct 18, 2012 at 9:07
  • \$\begingroup\$ @damien - Yep, that's it. (Always check if the output can sink the required current!) I also added a not to my answer that the alternative circuit inverts the logic. \$\endgroup\$
    – stevenvh
    Oct 18, 2012 at 9:09
  • \$\begingroup\$ About the sink current, if the absolute maximum rating is 20mA and the LED has 20mA forward current I guess it is not okay to use it this way right? The I/O could damaged? \$\endgroup\$
    – damien
    Oct 18, 2012 at 9:20
  • \$\begingroup\$ @damien - Not OK indeed: you should not operate the device at Absolute Maximum Ratings (AMR) for a longer time. That's a standard phrase in the AMR section of all datasheets. In that case you have to use the open-drain output to drive an external transistor. I added a schematic to my answer. \$\endgroup\$
    – stevenvh
    Oct 18, 2012 at 10:18
  • \$\begingroup\$ Thank you for your answer but in this case i don't see the purpose of using the OUTPUT as an open drain. I think it is easier to use it in push-pull configuration and just put a base resistance on the BJT. It seems to be the same isn't it? \$\endgroup\$
    – damien
    Oct 18, 2012 at 12:00

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.