Ohm’s law states that the current through a resistive conductor (a resistor) between two points is directly proportional to the voltage across the two points.
\(I={\frac {V}{R}}\) where I is current (amps or A), V is voltage (volts or V) and R is resistance (ohms or \(\Omega\)).
Example 1 – resistor calculation
I have a 5 V supply and I want to run a red LED at 8 mA.
We can see from the LED’s IV curve that at 8 mA the red LED will have a forward voltage of 1.8 V. That means there’s 5 – 1.8 = 3.2 V across the resistor. Using Ohm’s law we can calculate the resistance.
$$ I = \frac {V}{I} = \frac {3.2}{0.008} = 400~\Omega $$
390 \(\Omega\) is the closest standard value and that will be fine.
Don’t forget to check the power rating of the resistor! See Power calculations.
Notes
Note that the order of the components in this example doesn’t matter. The resistor can go between the +5 V supply and the LED or between the LED and ground. The same current will flow through the circuit and the same voltage drop will occur on the LED.