While looking for a basic task to get familiar with the Raspberry Pi and its GPIO pins, I decided that driving an LED sounded simple enough.

While investigating how to go about this task I've noticed that most instructions indicate to place a resistor between the GPIO pin and the LED. The size of the resistor varies by instructions, but typically in the range of 260 ohms to 1 kilohm.

However, none of the instructions indicate the reason for this nor do they indicate why they've chosen a (seemingly) arbitrary resistor size.

Why is a resistor even needed, and how would you know what ohms it should be?


The reason is common to all LED applications, not just Raspberry Pi (or the GPIO pins).

An LED can only pass so much current before it will destroy itself (very brightly!). The maximum current varies by the LED's size and colour, but for a medium-sized red LED can usually be assumed to be 20mA (check this value though, if you have the spec sheet for the LED handy - and tiny LEDs can only handle a tiny fraction of this).

A standard red LED usually has a voltage drop of around 1.7v, and so the value of the resistor can be chosen to pass 20mA at (voltage - 1.7). Assuming an input of 5v, this means a resistor that will pass 20mA at 3.3v, which (using Ohm's Law) gives us an absolute minimum resistance of 165 ohms.

The worst that can happen by using a larger resistor, is that the LED will be dimmer than its maximum brightness, and so in order to accommodate smaller LEDs that can only pass 10mA, it's not uncommon to use 330 ohms and above.

I'd put a 470-ohm resistor in for a 5v supply for a medium-sized red LED, and if the LED is way too dim then reduce it slightly.

If using a miniature red LED, then 1K ohms does not sound outrageous, and for more exotic colours (in particular blue, pink and white), you will want to calculate the value yourself.

| improve this answer | |

First of all, LED is a semiconductor diode. An current - voltage relationship inn diode (in general):

I = I(s)*[exp(eV/nkT)-1] (though this relation is not exactly real)\

And the most notable thing is that a small change in voltage produces larger change in current. And this is driving reason behind using a resistor with an LED in series.

Another thing is that generally the operating point of an LED is less than 5 volts (roughly 3.3 V). That is why we use a resistor of a proper value in series with the LED.

Go through Basics: Picking Resistors for LEDs. And you will get the idea of how to pick the proper resistor for a specific LED.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.