Maximum current draw from arduino pin

In the datasheet, I see that the maximum current output of a pin is 40mA. I have connected in series an LED with Vf = 1.2Volts and a 100 Ohm resistor so I draw 38mA which almost the max value. If I use 40kHz pulse with 50% cycle could I lower my resistor value to half or to a certain point and not burn my Arduino?

You should be OK.

It's generally "bad practice" to push things right-up to the limits so I wouldn't recommend it unless you have a "good reason". (In reality, your Arduino isn't going to burn-up if you draw 41mA, but I wouldn't recommend it... and you can't complain if it does burn-up.)

Note there is also a maximum-total of 200mA so be careful if you're running multiple LEDs from multiple pins.

No this is the only LED in my arduino and I don't draw current from other devices.

You have forgotten to add the internal resistance of the pin itself. If you assume ~25ohm (could be 20-40ohm), then LED current with a 100ohm external resistor is ~30mA. Nothing to worry about if you PWM that 50% (15mA average current). Leo..

vassilisamir: In the datasheet, I see that the maximum current output of a pin is 40mA. I have connected in series an LED with Vf = 1.2Volts and a 100 Ohm resistor so I draw 38mA which almost the max value. If I use 40kHz pulse with 50% cycle could I lower my resistor value to half or to a certain point and not burn my Arduino?

What is the importance of lowering the resistance value?

Nothing to worry about if you PWM that 50% (15mA average current).

That is where I disagree, using PWM does not get round the fact that the peak current is still exceeding the absolute maximum. The data sheet does not say about any rating for peak current so good practice is to assume that the absolute maximum IS the peak.

One place where I worked had a team that thought they could "get away" with that sort of thing with LEDs. The result was that in a year there was over 10% failure of units in the field. The customer called in the "catastrophic failure rate" clause in the contract, and we lost a bomb.Then we tried to get recompense from the manufacturer of the LEDs, but as the data sheet did not rate them for peak current then we coudn't touch them and lost an other bomb to the lawyers.

While PWM might mitigate against heat failure it does not effect the two other failure mechanisms of bond wire fracturing due to too much current being switched, causing mechanical strain, and free carrier depletion in the semiconductors due to too high a current density.

Calculated peak current with internal resistance of the pin is ~30mA. And current stays under the absolute maximum pin current of 40mA, even without the internal resistance. If average current would be 30mA (60mA peak), I could understand your concerns. Also, OP is using 40kHz PWM. Not some low frequency blinking rate that could put more thermal stress on the internal components of the chip.

OP, if you want to drive this IR LED with more than 30mA peak, use an external transistor. Leo..

vassilisamir: ....could I lower my resistor value to half or to a certain point and not burn my Arduino?

Do you have an allergy to transistors?