0
\$\begingroup\$

I would like my LED to run at 40mA (max current for ATmega328p IO pin). The LED datasheet says that 2.2V is max forward voltage. I am trying to calculate which resistor to use.

According to the calculations I have done, 3.3V (voltage of IO pin) - 2.2V (max voltage of LED) = 1.1V. 1.1/0.04 = 27.5 Ohms. I only had a 33 Ohm resistor and that would mean I should get 33mA. I got about 30 according to the multimeter, so roughly correct.

When I powered the LED from the IO pin, I only got 17mA. What's going on here? Should I decrease the resistor value until I get the 40mA I want, or is this dangerous for the chip?

Thanks.

\$\endgroup\$
  • 2
    \$\begingroup\$ The MCU pins are not designed to be used at a load of 40mA like that. That specification is one provided to show the absolute maximum current that the pin could support without damaging the part. Use the MCU pin at a much more reasonable current level and buffer the pin with a transistor or MOSFET that is designed to handle higher currents. \$\endgroup\$ – Michael Karas Aug 1 '18 at 10:03
5
\$\begingroup\$

The pin on your MCU won't sustain a nominal voltage of 3.3 volts except under very light loading conditions. What I think is happening is that as you draw 17 mA, the pin voltage is drooping down to something smaller than 3.3 volts. You can check this with a multimeter of course.

I would like my LED to run at 40mA

Trying to take 40 mA from your MCU pin is ill-advised - you should consider using a buffer transistor. Read this answer for clarification and note you should never design something that is close to abusing the absolute maximum ratings of a part.

If you look at the ATmega328p data sheet this table is in section 32.2. (Common DC Characteristics): -

enter image description here

With Vcc at 3 volts the output voltage is only guaranteed to be 2.3 volts at an ambient of 85 degC with 10 mA load. This is an effective output series resistance of 70 ohms. At 105 degC the output resistance is 90 ohms and, if you did a rough extrapolation to a lower temperature like 25 degC it might be 30 ohms or so.

With a 40 mA demand placed on the pin this means the output voltage will drop from 3.3 volts to about 2.1 volts and this is less than the LED forward voltage. Sure you can try this and get something like 40 mA but there are no guarantees this will always happen. That is what the data sheets are for - to guide you in making some common-sense judgements.

\$\endgroup\$
  • \$\begingroup\$ Yes there was some voltage drop on the pin. i would rather not use a transisor if i dont need to. would reducing the resistor so that the led is sourcing 30mA be appropriate? i should also add that the led wont be on constantly. it is being used to react to sound and adjust itself to the amplitude via PWM. this would decrease the burden of overheating i would imagine. \$\endgroup\$ – user2105725 Aug 1 '18 at 10:44
  • \$\begingroup\$ The worry is your MCU's ability to supply this sort of current without it causing other problems. If you read the data sheet the supply pins are only rated possibly at twice than the individual IO pin currents and if you have several LEDs or other IO loads you can rapidly run out of steam so to speak. \$\endgroup\$ – Andy aka Aug 1 '18 at 10:49
  • 1
    \$\begingroup\$ @user2105725 - You are free to abuse the MCU pin as you wish as long as you keep that solution for yourself. If on the other hand if you intend this gadget you are designing to be used by others and intend it to keep working you should heed the advice to not use parts at their absolute maximum ratings. There are just too many other factors that change things so all of a sudden the usage model changes to be over the absolute maximum ratings. \$\endgroup\$ – Michael Karas Aug 1 '18 at 10:54
  • \$\begingroup\$ @Andy aka with regards to your update. what is the reason for this unpredictability? is it generally always a good idea to use an external resistor if the current draw is above a certain amount? as a rule of thumb what might this current be? thanks. \$\endgroup\$ – user2105725 Aug 1 '18 at 11:47
  • \$\begingroup\$ I'm unsure what you mean by unpredictability? As a general rule, work within the limits imposed by the data sheet. In fact that is a golden rule in my book. If the data sheet tells you that a 10 mA draw drops 0.7 volts from an IO pin then that is an equivalent output resistance of 70 ohms. Extrapolation as per what I did to conclude the output resistance at 25degC of 30 ohms is reasonable. I would never drive an LED directly from an IO pin of any MCU unless the data sheet was explicit about it. \$\endgroup\$ – Andy aka Aug 1 '18 at 12:12
3
\$\begingroup\$

You forgot to account for the impedance of the output pin, nominally 25ohm at 20degC for AVRs. Once you do so you will find that you need almost no resistor at all.

Of course, drawing so much current from the pin will cause the output driver to heat up and the impedance to drift away from that, so you will want to use an external constant current driver regardless.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.