33

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
38

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 | |
4

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 | |
2

The Question:

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

The Short Answer:

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 Better Answer

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.

enter image description here

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.

enter image description here

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.


OTHER REFERENCES:

  1. Practical Applications of Current Limiting Diodes

  2. Advantages of Constant Current Regulators (CCR) in Driving LEDs - A Video

  3. Full retro article fm "Electronics World" when constant current diodes were 'new'

  4. The FET Constant-Current Source/Limiter, Vishay AN103

  5. Transistor Current Sources and Mirrors - A long-ish 18 min Video

  6. Introduction to Field Effect Transistors JFET MOSFET

  7. A current source based on a JFET

  8. For the ambitiously inquisitive, this paper offers an idea for a truly unique project: use a Raspberry Pi to measure Planck's constant. You're not likely to find a tutorial on that one! But then again...

| 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.