Limiting current flowing through a LED is very important for some applications. A LED in circuit behaves differently than a resistor. The resistor shows linear characteristics described by the Ohm's Law formula V = IR. In other words, if we increase the voltage across the resistor, the current flowing through the resistor will increase proportionally to the voltage increase, provided that the resistor's value remains the same. However, a LED does not show linear characteristics. LED behaves according to the non-linear I-V characteristic of a diode.
For example, any LED's datasheet provides recommended forward voltage (usually between 1.5-4V for LEDs), which must be reached to turn ON the LED. However, when voltage exceeds the recommended forward voltage value, the LED's internal resistance quickly decreases. Therefore, the LED will begin to draw a substantial current and in some installations may burn out. To address this problem, a resistor is placed in series with the LED to keep its current at a specific level called recommended forward current. This resistor is called current limiting resistor.
According to the diagram above, in order to calculate a current limiting resistor, we need to know three values in order to determine the value of current limiting resistor.
i = LED forward current in Amps (provided by the LED's datasheet)
Vf = LED forward voltage drop in Volts (provided by the LED's datasheet)
Vs = supply voltage
These three values are inserted to the equation below to determine the value of a current limiting resistor:
i = 20 mA or 0.02 A
Vf = 1.7 Volt
Vs = 5.0 Volt
R = (5.0 - 1.7)/0.02 = 165 Ohm