I apologize if this question is not well formed. I am an amateur in this field.

I have the requirement to independently control a plurality of RGB diodes from a single microcontroller. Each diode has 3 input pins (each corresponding to one of R, G, & B). This is the led.

I want to hook each of these diodes up to a Adafruit Trinket; however the Adafruit Trinket only has 5 GPIO pins, which, I am guessing would only allow me to control the RGB spectrum of one diode and 2 colors on another diode. (3 + 2 = 5).

As per my requirements, I need to independently control 6 diodes, which, as I understand, would require 18 GPIO pins; far more than are available on the Trinket.

I am wondering if there's some other smart way to somehow control the full RGB spectrum on one diode using just one GPIO pin; or if there's some standard way to control these diodes that I am not familiar with; for example, extending the number of GPIO pins on a board, etc.

If not, and each diode does require 3 GPIO pins, I wonder how someone would go about prototyping a device that requires many GPIO pins yet also needs to be physically very small (similar in size to the Trinket). Would I just go about using a larger board that accommodates more GPIO pins and plan on downsizing considerably when the custom PCB is made?

Thanks in advance.

  • \$\begingroup\$ By "full RGB spectrum" do you mean all of the CIE color coordinates possible from that RGB LED? As well as varying the perception of brightness? Or something less complex? \$\endgroup\$
    – jonk
    Commented Jan 20, 2019 at 6:12
  • \$\begingroup\$ Thanks for the response. Sorry; yes, full CIE color coordinates from the LED. \$\endgroup\$
    – nikk wong
    Commented Jan 20, 2019 at 6:18
  • \$\begingroup\$ I got lost. Do you have 1 LED and you need to control it with one pin? Or do you have 6 LEDs and need to control them with 6 pins? Because the 2nd problem is much easier to solve. \$\endgroup\$
    – The Photon
    Commented Jan 20, 2019 at 6:23
  • \$\begingroup\$ I have 6 LEDs and need to control them with 6 pins. That's awesome to hear! :) \$\endgroup\$
    – nikk wong
    Commented Jan 20, 2019 at 6:24
  • 1
    \$\begingroup\$ Where you need something compact, you don't use a limited off the shelf board. QFN package MCUs (or multichannel LED drivers) have lots of I/O in a small space. However, they will require some experience to work with. Think for a minute about history: electronics got smaller as technology got more sophisticated; if you are constrained to work with trailing-edge tech, you are constrained to build big. But you can build big to figure out what you are trying to do, and then miniaturize. Don't forget to consider things like your power source when doing that too. \$\endgroup\$ Commented Jan 20, 2019 at 6:47

2 Answers 2


There are several ways to use fewer microcontroller pins than you have diodes. Which route you choose depends on details like required brightness, whether you want to buy or build stuff, how much you want to spend, form factor, size etc etc.

An RGB LED contains 3 independently driven diodes. I'll refer to this as '3 diodes' or 'an RGB', so we don't over or under count.

Simplest solutions first

a) One diode per pin, as in your question. This is the simplest. 5 pins will drive 5 diodes, or nearly 2 RGB LEDs. Each pin can be PWM'd to control individual diode brightness, so you can get the full available colour gamut from one of the RGB's.

b) Buy WS2811 or 2812 driven RGBs. These are usually available in a long strip. The entire strip can be driven from one or two GPIO pins (depending on whether it's a '1 or a '2) and strips can be cascaded and still need the same number of pins. The strips often have break lines with pads either side between the diodes so you can separate the RGBs, wiring across the break with some lengths of wire.

The timing required on the drive pins is a bit tricky, but most popular MCUs have driver libraries available for these ICs.

Or you could buy the WS281x ICs themselves and build with them, but it's far cheaper and easier to get the driven RGBs. WS2811 WS2812.

As jcaron comments below, APA102 is another option (9822 being a common clone of that), with more conventional SPI programming, and a much higher PWM frequency (which improves on the horrible 281x flicker (though some later 281x's have apparently higher PWM frequency)), but they appear to be much more expensive than 281x's at the moment (early 2019).

c) Multiplexing. Each diode spends some time off, so you get lower maximum brightness. Each GPIO pin drives the anode or cathode of several diodes. With 5 pins, you would typically split them into 2+3, so could drive 6 diodes, or 2 RGBs. You will typically need a current booster to drive the common lines, unless you want to suffer a further brightness hit. If you decode the device selection lines rather than using them directly, so use the group of 2 lines to select one of 4 devices, you could drive 4 RGBs.

d) Charlieplexing. Like multiplexing, but a more subtle arrangement, that dynamically reuses the undriven common pins to drive the other diodes. You can drive up to n(n-1) individual diodes, which is 20 in your 5 pin case. When the diodes are physically grouped into 3s as in RGBs, there will be a restriction due to this, but you can still drive 5 RGBs with 5 pins (and add another 5 single diodes to the matrix as well).

e) GPIO expansion. You can use ICs like HC595 to increase the effective number of output pins on an MCU, this has 8 outputs and can be cascaded indefinitely for more outputs. Most popular MCUs have libraries which simplify the driving of such expanders. HC595 has lower current output than typical MCU pins and will not light LEDs as brightly without drivers, though 6mA will still get a reasonable brightness. There are other ICs available with more pins, and higher current outputs.

  • \$\begingroup\$ Thank you so much for the thorough response. I am looking at the WS2181 now, how does it change the colors separately instead of passing commands down the series? I am very curious and googling but not finding much. Also, what makes the timing difficult? Can you briefly touch on what you're referring to so I have a point of reference when I try to get this thing working? Thank you. \$\endgroup\$
    – nikk wong
    Commented Jan 20, 2019 at 8:28
  • \$\begingroup\$ I think it's a typo, it must be WS2812. Finally, they have 8bit per color, hence 24 per led. One simply sends all RGB values for all LEDs in one go. When no more data is received for 50us, the LEDs switch to the new color. Each bit is a high followed by a low, together 1us long. The length of the high defines if it's a 1 or 0, and is more important than the length of the low. This relaxes the tight timing a little. \$\endgroup\$
    – sweber
    Commented Jan 20, 2019 at 8:49
  • \$\begingroup\$ I addition to the WS2812 you may want to consider APA102 LEDs. They’re a little bit less common, but use standard SPI rather than PWM which makes them easier to use in many scenarios. Adafruit (and others) call them DotStar (NeoPixel = WS2812). \$\endgroup\$
    – jcaron
    Commented Jan 20, 2019 at 11:20
  • \$\begingroup\$ @nikkwong whoops, sorry, typo, added links to answer \$\endgroup\$
    – Neil_UK
    Commented Jan 20, 2019 at 11:21
  • \$\begingroup\$ @jcaron puzzled! Is an apa102C a 6 pin rgb led with builtin driver, or a 15 pin driver IC? Admittedly I've only looked at one pdf \$\endgroup\$
    – Neil_UK
    Commented Jan 20, 2019 at 11:28

WS2811 ICs, use one per RGB LED. https://www.mouser.com/ProductDetail/Adafruit/1378?qs=GURawfaeGuC97B4u3AEc0g%3D%3D&gclid=EAIaIQobChMIoNTpkY793wIVl8DICh33qQPmEAQYAyABEgILf_D_BwE

Or TPIC6B595 or TPIC6C595. 150mA, 100mA current sink outputs.

Or WS2803, with 18 PWM outputs for RGB LEDs.

These are the guys that make the WS series of chips


Only difficulty is finding where to purchase them at.


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.