Control six separate RGB LED strips with a single Arduino Nano
If you’re used to working with individually addressable RGB LEDs, then that title probably has you scratching your head — controlling six NeoPixel strips is easy with an Arduino, since each strip only needs a single I/O pin for data. But we aren’t talking about individually addressable LEDs; we’re talking about conventional common-anode RGB LED strips and Trevor Makes recently uploaded a video demonstrating how to control six of them with one Arduino Nano.
A common-anode RGB LED has four leads: one anode, and one cathode for each color. The anode always connects to the positive side of the circuit and connecting each cathode to the negative side of the circuit allows current to flow through that specific LED. A common-anode RGB LED strip expands on this concept, with all of the cathodes chained together by color channel. The operation is the same: connecting a color channel cathode to the negative side of the circuit causes all of the LEDs to light up in that color.
The Arduino Nano has 20 available digital I/O pins and Trevor needed two of them for a serial connection. That left 18 pins, which is enough for the three cathodes for each of the six RGB LED strips. If all he wanted to do was set each strip to a single full-brightness color, then this would be straightforward. But what if he wants something more complex, such as brightness adjustment of each channel to achieve more granular color mixing?
If the 18 pins were all analog, one could adjust the voltage for each color channel of each strip to adjust the brightness. But these are digital pins, which can only be on (HIGH) or off (LOW). Fortunately, there is a cheat: pulse-width modulation (PWM). This modulates power to a pin and when that happens fast enough, it effectively lowers the perceived brightness of LEDs. But the ATmega328P microcontroller used on the Nano can only produce six independent PWM signals — not enough to control all 18 cathodes.
Trevor explains how he got around that limitation by implementing timer-based hardware interrupts. This is an unusual and clever use of interrupts and it lets the user control the individual brightness of every color channel of every LED strip. Trevor discusses the technique in detail in his video, and also has example code and schematics available on GitHub.