# Lots of LEDs in a chain

I need to control about 90 LEDs with a Raspberry Pi. I am thinking of doing with with 3 chains of 30 LEDs, so I can control each set of 30 LEDs independently (turn 30 on and off at a time) and change their brightness (using `GPIO.PWM`). Do I just need to just have one resistor at the end of the chain of LEDS example (`gpio_resistor_led_led_led_led_led_ground`)?

I am thinking of using a Pi Zero and these LEDs

should this work?

• Commented Apr 2, 2018 at 16:12
• Get an APA102 based LED strip. These are easily controllable from the Pi without the need of special hardware or software.
– joan
Commented Apr 2, 2018 at 17:11

"Should it work?" Probably not... as in all things, how you do it will determine how well it works. Your posting implied that you were considering driving each string of 30 LEDs `in series` with a GPIO pin. Putting the LEDs in series is a good idea, but I hope that @Ghanima's answer has convinced you not to spend any time pursuing your idea of driving them with the GPIO pins. That simply will not work very well at all! But on to a proper answer...

Driving 30 LEDs in series is definitely "do-able", but you will need to spend some time and effort designing or selecting an `interface` circuit. This `interface` circuit will be positioned between your GPIO pin(s), and the series string of LEDs as shown in the schematic below. Its realization may require more than one item of hardware.

simulate this circuit – Schematic created using CircuitLab

Since LEDs are `current driven devices`, your `interface` should be a current source instead of a voltage source. In other words, it will regulate its current output at a particular value - a specification determined by the LEDs you choose, and the brightness you want. From the LED page on Amazon you referenced, the maximum drive current required is 20 mA, and the maximum forward voltage drop is about 3.5 v. Using Kirchoff's Laws and doing the math yields the following:

• the constant current `interface` must source 20 mA
• the `compliance voltage` of constant current `interface` must be `30 x 3.5 =` 105v!

And so that means that a device in this class might be appropriate for the `interface` in your project. Since the output voltage exceeds 70v, it also means that you'll need to investigate the rules and regulations pertaining to its deployment.

But your interface design isn't complete yet (assuming you're using a device similar to the one above) as you won't be able to interface this device directly with a Pi Zero's GPIO. Something like a `solid state relay` may be required to complete the design of your `interface`.

Of course this is just a brief outline. It neglects several details, but hopefully gives a fairly thorough answer to your question of "should this work?". Please post any follow up questions here, and good luck with your project.

Mind you that you will have to switch a voltage in the range of 50 to 100 V - 30 times the forward voltage of each individual LED - thus a high voltage is required that poses the risk of electrical shock. That alone might be reason enough to change the plan.

Furthermore it will not work directly off the GPIO pin but requires an additional switching transistor that is able to handle a voltage that high. Other than that a circuit of series LED with a single resistor is, in principle, ok.

For this application however I would suggest to limit the number of LEDs connected in series according to the voltage of a suitable power source, i.e. 12 or 24 V, whatever is available. The number of resulting strings then determines the number of GPIO pins required. Again connecting this many LEDs directly to the GPIO pins might not be a good idea either depending on the desired current through the LEDs and the current the Pi can provide.

See Raspberry Pi Power Limitations and What are the Electrical Specifications of GPIO pins? for more (emphasis mine)

In simple terms you can safely draw 16mA from a GPIO pin (the default is 8mA with defined logic levels, but this can be reconfigured). There is no defined limit for total current, and with the modern power supply you could, in principle, draw this from all 26 pins, but prudent design would suggest a more modest limit.

An external driver should do the trick, e.g. an I2C driver/multiplexer or the ULN2003 darlington transistor array (or here or here) or the ULN2803.

• so should i connect the 3v leds in pairs to the GPIO (25x GPIO_resistor_led_led_ground) so using 25 GPIO i can get 50 LEDs total? that should suffice Commented Apr 2, 2018 at 15:44
• you don't have to connect them in series, they could be wired in parallel so you don't need high voltage. But it will be a lot more current then what the pi gpio pins can supply, so it would need to be powered externally, and switched via a transistor or the like Commented Apr 3, 2018 at 22:41