In most of the getting started tutorials for Arduino (like this Blink example) it is recommended that we have place a 220 Ohm resistor. I know that it is calculated using Ohms Law, but I am interested to know how this value is calculated?

Initially I thought it was to protect the LED. I followed this guide from Evil Mad Scientist. The articled explained that a typical Red LED has a voltage drop of 1.8 V and a current of abound 25mA and Arduino Pin has an output of 5V. Using these values and the formula from the article, the calculation is

V = (power source) - (Voltage Drop) = 5V - 1.8V = 3.2 V I = 25 mA

so R = V/I

R = 3.2/0.025 = 128 Ohms.

Which is not equal to 220 Ohms.

Then, I came to know that we should also protect the Microcontroller pin. I saw from Atmega 328P datasheet, that the maximum DC current in a Pin should be 40mA. So using this value

V = 5V and I = 40mA

R = V/I = 5/0.040 = 125 Ohm.

Which is also not near to 220 Ohm.

I did a research about it and the more I read about it, the more I am getting confused. Can someone help me understand how this value is calculated? Thanks for your time.