LEDs and Resistors

L

In a previous post, I mentioned that you need to use a resistor when connecting an LED to the GPIO, but how do you know what value resistor to use?

The reason we need a resistor is because the LED will only stand so much current before it blows.

There are 2 output voltages from the GPIO pins, 3.3v from pins 1 and 17, and 5v from pins 2 and 4.

Lets say you have a 5mm blue LED from maplin (Something like this) there are 2 important bits of information you need to calculate the resistor to use with it. The Forward Voltage and the Forward Current.

For the LED here, the Forward Voltage is given as 4v and Forward Current as 30mA. So using the 5v output from the GPIO, what resistor do we need?

The way to work this out comes down to the V=I x R formula of Ohm’s Law

As we’re working out the R part we can change this to V/I = R

The V in the formula is calculated by taking the LED forward voltage away from the power supply voltage:

5v - 4v = 1v

That is the V part of our formula, next we need the I part which is the current for the LED. We could use the Forward Current given but this is the Maximum the LED should have, it’s usually better to give slightly less than this so we’ll use 25mA. Giving the full 30mA would be fine, but would give off more heat and drain batteries (if you were using them to power the LED) a lot quicker.

Converting the 25mA into A gives 0.025A.

Therefore putting this into the formula we get 1v/0.025 = R

This gives R as 40 (ohms).

We might not have a 40 ohm resistor, but most resistors have a tolerance of +/- 5 or 10%, so the resistor might not be the exact value given anyway. We would usually find the closest higher rated resistor we can and use that.

To calculate a resistors resistance, you look at the coloured bands on it and use the following table to work it out.

The most common resistors and the kinds you're likely to be using with LEDs powered by the raspberry Pi have 4 coloured bands. The first two are used to calculate the value, the third is a multiplier and the forth is the tolerance. There is usually a larger gap between the third and forth bands this is how you can work out the order of the bands. If there are 5 bands then the the first 3 are used to calculate the value, the forth is the multiplier and fifth is the tolerance.

Colour1st Band2nd Band3rd BandMultiplierTolerance
Black0001Ω
Brown11110Ω±1%
Red222100Ω±2%
Orange3331KΩ
Yellow44410KΩ
Green555100KΩ±0.5%
Blue6661MΩ±0.25%
Violet77710MΩ±0.1%
Grey888±0.05%
White999
Gold0.1Ω±5%
Silver0.01Ω±10%

Tags

android apt-get audio breadboard cases circuit debian first boot gpio hardware hats and phats leds linux media centre operating system photos pi zero pibow raspberry pi board raspbian raspbmc screenshots sd card terminal updating video wifi wireless network xbmc