1
\$\begingroup\$

I'm looking to buy resistors for a Raspberry Pi project, but am getting conflicting information on which resistance to use for my LEDs.

I will have three LEDs. The voltage from the RPi GPIO pins is 3.3 V. At 20 mA current, the forward voltages are 1.85-2.5V, 2.2-2.5V, and 3.0-3.4V for the red, green, and blue LEDs, respectively.

Using this website, I calculated all of the resistors to be around 15-82 ohms, which seems low to me, especially considering this Adafruit starter kit comes with 560 ohm resistors for the (near-equivalent) LEDs...

Can someone please advise me or help explain the discrepancy? Also, these LEDs will not be in parallel or series; each will be attached to a different out pin on the RPi.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I think 20mA is quite a huge current for a single LED... generally 20mA is the max current an ordinary LED can sustain... In most cases it is 2-3mA which delivers adequate brightness. you can increase the resistance and thus limit it to this level of current \$\endgroup\$ Commented Aug 3, 2014 at 17:13
  • 1
    \$\begingroup\$ Where did the 20mA come from? That's a really high current for good visual brightness with a modern LED. Also you'd need -5 ohms resistance if the Blue led was 3.4V and your driver is perfect. Probably more like -50 ohms. I have not checked Digikey, but last I looked the resistor values stopped around 0\$\Omega\$ \$\endgroup\$ Commented Aug 3, 2014 at 17:13
  • \$\begingroup\$ Here is the product page at Adafruit. Specifies "2.2-2.5V Forward Voltage, at 20mA current" - does that just mean it can go up to that current? \$\endgroup\$ Commented Aug 3, 2014 at 17:15
  • \$\begingroup\$ thats right Jeff. Also in the site that you gave you have to give the supply voltage (i.e. the battery you connect) not the forward voltage. Double check it. \$\endgroup\$ Commented Aug 3, 2014 at 17:19
  • \$\begingroup\$ Thanks, @RaghunathV. The website asks for both source and forward voltages. \$\endgroup\$ Commented Aug 3, 2014 at 17:22

5 Answers 5

1
\$\begingroup\$

The 20mA rating of your LEDs is probably the recommended maximum current. Most LEDs will produce light at much lower currents - I find 5 mA is sufficient for indicator light use.

Try the LEDs with different resistors to see what current is actually required to produce sufficient light for your application (more current = brighter light).

Also, check the maximum current the Pi GPIO pins can handle - I have a feeling it is less than 20 mA, but can't check at the moment.

\$\endgroup\$
2
\$\begingroup\$

The situation is a little complex. IMHO a reasonable source of information is Gert Van Loo, one of the R-Pi designers.

The total current you can draw through all of your LEDs is limited by both the R-Pi power supply, and by the current capacity of the internal switches (within the chip) connected to the pins.

Gert Van Loo recommends drawing no more than ~3mA/pin (the same document explains "The raspberry-Pi 3V3 supply was designed with a maximum current of ~3mA per GPIO pin"; that was what they allowed when designing the R-Pi power supply). R-Pi has 17 GPIO pins, so I interpret the safe limit as 3*17 = 51mA total for all active GPIO pins combined.

You might get away with drawing more current from the GPIO pins, depending on what else is drawing current; the GPIO pins are competing for power with other peripherals connected, and the R-Pi subsystems used. So, for example, if there are no USB devices connected, there is a couple hundred milliamps more available.

Gert also says the maximum a single GPIO pin can supply, and still reach the minimum voltage levels specification is 16mA.

Gert provides some of the spec:

VIL=0.8V means that if the output is Low it will be <= 0.8V.
VIL=1.3V means that if the output is High it will be >= 1.3V.
Thus a drive strength of 16mA means:
If you set the pad high you can draw up to 16mA and we still guarantee that the output voltage will be >=1.3V.

Trying to switch on an LED which requires 3.0-3.4V, is likely to fail to light the LED consuming 16mA

The chip might not light an LED which requires 2.2-2.5V if it consumes 16mA.

It might not light an LED that only needs 1.85-2.5V if it consumes 16mA. I'd be very surprised, but the chip is still meeting its specification.

So note, the voltage available at the pin varies depending on the current drawn. When you are driving voltage sensitive devices, use a small current to ensure the voltage is actually available.

More confusing, LOW<=0.8v, 1.3V<=HIG is the specification. So some or all chips might do better in practice, it might vary from batch to batch, and will vary according to temperature. So just because someone has posted better results, does not mean your R-Pi can achieve the same thing.

Next how many pins could you use?

You could draw 16mA's from 3 pins (48mA) and be 'safely' within the designers assumptions. You might safely draw 16mA from more pins, but that would be competing with assumptions the designers have made about other consumers of power.

If you want to use more pins, and remain within the designers assumptions, ensure the total current used by all of the pins is under 51mA. You could use 10 pins at 16mA each, as long as no more than three are active at any one time.

Everyone else has already said that 20mA is a lot of power from an LED. If all you need is some indicator lights, then 3-5mA is plenty for most ordinary LEDs. You could get high-efficiency LEDs, which work okay at 1-2mA. You have a way to calculate resistor values, so I would recommend using 3mA as the current. You might also assume the voltage has sagged a bit to 3.0V, and decide what that implies for the Blue LED.

However, if those LEDs are needed to do some other job, for example, be part of a sensor system, then that current really might not be enough, and it really might not be practical to drive them from an R-Pi pin. If that is the case, it would help us if you explain what you ned the LEDs to do.

Engineers try to ensure every instance of a product works, and so typically adopt conservative assumptions, like only using 50% of specified available current, and assuming worst case voltages.

Your project might be a one-off, and you might need to get very close to the specification, in which case be prepared for things to get hot, or need cooling, or switching off occasionally, and maybe have intermittent faults.

\$\endgroup\$
1
\$\begingroup\$

The values are correct for 20mA current, but most of the time you don't want to drive your LEDs so hard. Depending on the efficiency and function of the LEDs, 1-5mA forward current may be sufficient.

\$\endgroup\$
1
\$\begingroup\$

Something like a 330 ohm resistor will do. Pretty much anything 220 or above and below 1k should do the trick. That calculator thing will just be minimums or production calculations. For a little project it doesn't matter so much. I always use a 330 to protect my LED's.

\$\endgroup\$
1
\$\begingroup\$

It could be a good exercise to gor through and calculate the resistances yoruself choosing some middle of the road current value. There is such a thing as an LED that is bright to the point of being quite annoying. Check the data sheet for the diode drop and make sure to include this in your analysis.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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