Ohm's Law (Vive la Resistance!)
An overview of 'Ohm's Law', which is frequently used determine which current-limiting resistor value is required.
In almost any electronic device, the most common component used is the simple 'resistor'. Resistors, as their name implies, are used to restrict the flow of current between different components (to say 20 mA for an LED). Resistors are essential, since without them your components would quickly go up in smoke, your LEDs would burn out in a flash, and other forms of unpleasantness would almost certainly happen. That's easy enough to understand (too much current = bad), but it isn't always obvious which particular resistor you should choose for a specific situation to ensure that you have just the right amount of current. That's where Ohm's Law comes into play.
Ohm's Law states that "the current through a conductor between two points is directly proportional to the potential difference or voltage across the two points, and inversely proportional to the resistance between them". If that makes your head spin, it can also be represented with this simple formula (where V = Voltage, I = Amps, and R = Resistance in 'Ohms'):
V = IR
A commonly used component in many electronics projects is an LED. They come in a wide variety of colours, shapes, and sizes, and are a useful way to indicate the current state of the device (powered on, transfer in progress, etc.). The common 5mm round through-hole types or the rectangular surface-mount varieties often uses around 20mA of electrical current at their brightest strength. Pass that upper limit, and you will quickly burn the LED out and it will be useless to you. As such, it's important to limit the amount of current that can flow to the LED to a predetermined maximum level. Since we know the maximum amount of current that we want to allow (20mA), and we almost certainly know the voltage rating of our board (I'll assume 3.3v in this example), we can use Ohm's Law to determine exactly which resistor value we need to place between the LED and the power source to make sure our LED never draws more than 20mA current.
Voltage = Amps * Resistance
3.3V = 0.02 * R
R = (3.3 / 0.02)
R = 165 Ohms
Essentially, all you really need to pay attention to is that third line. You simply need to divide voltage (3.3) by amps (0.02). If you're wondering where we got 0.02 from, it's because there are 1,000 mA in 1A, se we simply divided 20mA/1000 to get the equivalent value in Amps (0.02A). The result of this equation will give you the Ohm rating required for your resistor (165 Ohms).
Optimal Resistance for LEDs
While the above formula will almost certainly give you a safe resistor value when working with LEDs, if you want the optimum brightness for your LEDs you should also take into account their 'forward voltage' or 'voltage drop' when making your calculations. The slightly modified formula you should use for LEDs is as follows:
Vs - Vf
R = -------
If R = Resistance in Ohms
Vs = Supply Voltage (ex. 3.3V)
Vf = Forward Voltage or Voltage Drop
If = LED Current Rating (ex. 20mA or 0.02A)
For an LED with a forward voltage (AKA voltage drop) of 1.8V, and a maximum current rating of 20mA, we would get the following results using a 3.3V supply:
R = (3.3V - 1.8V) / 0.02mA
R = 1.5 / 0.02
R = 75 Ohms
The ideal brightness for an LED with the aforementionned characteristics, then, can be had by using a 75 ohms resistor. However, it's strongly recommended to use a slightly higher resistor value, just to take into account any variation in the resistor (for example, 100 Ohms instead of 75).
If you're feeling particularly lazy, or just want to confirm your calculated values, feel free to use the simple calculators we've provided on the right-hand side of this page!