# Why is a resistor needed for LEDs?

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?

• A resistor is the cheapest form of a current regulator. – Dmitry Grigoryev Sep 29 at 12:53

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.

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.

### The Question:

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

A resistor is not needed. The parameter of primary importance is the current to be passed through the LED, and that value is obtained from the forward current (IF) rating in the spec sheet (Example). However if a resistor is used, its value is easily calculated from Ohm's Law, the value of IF and the supply voltage (Vsupply):

R = Vsupply / IF

A resistor is not needed to drive an LED. What is needed is a means to limit the current that flows through the LED. Resistors offer an expedient means for limiting the current through an LED to safe levels, but they have two downsides:

1. Resistors are inefficient:

A resistor converts all the electrical energy it consumes into heat. Consequently, they are 100% inefficient... and who needs more heat in their electronics?

2. Resistors cannot compensate for changes in supply voltage

For several reasons, LEDs may not be powered from the same bus used for sensitive electronics in many applications. Rather, they may be powered from loosely-regulated sources, and/or at some distance from the "brains" where the decisions are made to illuminate an LED. Poorly-regulated power sources are a fact of life, but that does not diminish the need for a stable luminous output from an LED.

### The Current and Voltage Relationship in a LED:

To understand why it is necessary to limit the current through an LED, we will need to understand this:

Once the LED is forward-biased, small increases in the voltage cause exponentially greater current flow. If the current is not controlled, the LED will eventually be destroyed.

This non-linear relationship between voltage and current in a diode was described in 1949 by William Shockley with an equation that now carries his name - the Shockley diode equation. LEDs generally follow Shockley's equation, but as the figure below shows, the parameters (e.g. Is) of the equation vary depending upon the band-gap of the semiconductor material used - which determines the color of the emitted light. The prominent feature of these V-I curves is the slope of the curve as the input voltage to the LED increases. ### Conclusion: LED Current Must Be Limited to Avoid Device Destruction

That said, there are several methods for limiting the current flow through the LED - a resistor is only one method, and as mentioned previously, it is not "the best" method.

Here are two alternatives for controlling the current through an LED:

1. LED drivers:
There are a wide variety of LED drivers available that won't require a single resistor; some offer control inputs to adjust their constant-current output and other features. Manufacturing sources for these devices include: Analog Devices, Texas Instruments, Maxim, Microchip, and others. Available through various distributors for as little as \$0.20 for a qty of 10; for example:.

2. Constant-current diodes: Constant-current diodes are interesting devices: they are manufactured as a junction field-effect transistor (JFET) with the gate and source terminals tied together. These devices are also sourced by several manufacturers, and available through distribution at reasonable prices.

The References below have further details for those interested.