Addressable LED strips, sometimes called Digital LED Strips, are a blast to work with. They are a long strip of RGB LED lights where every light can be individually set to a specific color. Analog LED strips only allow you to change the color of ALL the lights at once. In this tutorial, we’ll be focusing on the digital variety.
|Mokungit 3.2’ 60 Pixels Programmable Individual Addressable LED Strip Light|
|Breadboard & Jumper Wire Kit|
|Arduino Uno R3|
- Connect the RED (+5v) from the strip to 5V on Arduino.
- Connect the WHITE (GND) from the strip to any GND on Arduino.
- Connect the GREEN (DIN) to any of the digital pins on Arduino (for example, digital pin 3).
- If your strip includes two additional wires, these are used with longer strips where the Arduino is not able to supply enough current to power all the lights.
Writing all the code from scratch to work with one of these can be a bit intimidating, so we’ll use the MakerVision app to get a jump start.
Here’s the simplest program you could write. This program turns every pixel green.
Another example, this time setting half the LEDS green and the other half red.
This is a more advanced program that slowly turns on every LED, one after another, and then turns them all off before repeating.
If you’re just looking to start using the light strip - congratulations! You’re ready to go! If you’d like to learn a little more about how it all works, keep reading.
Most Addressable LED Strips have 3 wires coming from them. Some of them have 5. If you have a strip with 5 wires you can safely ignore the extra 2 wires. The extra wires are used when you’re chaining together a bunch of strips and you need to supply a fresh power source to a downstream strip.
Two of the three wires are used to provide power (White & Red), while the third (Green) is used to tell each LED what color it should switch to.
With only one actual wire dedicated to communicating with the strip, how are we able to communicate a color for every single LED? The answer lies in a very creative combination of hardware and software, which we’ll explore next.
Digital electronics communicate by sending patterns of 1s and 0s to each other. A “1” is communicated by applying a voltage to the wire, making it “HIGH” or on. A “0” is communicated by the absence of a voltage on the wire.
Another key concept here is that we can express color in whats known as the RGB color model. Colors are expressed as combinations of Red, Green and Blue light. Each color is a value between 0 (no light) and 255 (highest amount of light). Here are some example colors, with their corresponding RGB values:
So, we can express the color red by saying it’s RGB(255,0,0) - a lot of red, no green and no blue. If we want to actually send this color over the small green wire, we cant just send “255,000,000” though, because we can only send 1’s and 0’s. That’s where binary comes in. The number 255 is expressed in binary as “11111111”, and the number 0 is expressed as “00000000”.
This is how we communicate colors to the LEDs. We send RGB values, expressed in binary, one after another. Each LED will read the first RGB color, and then pass the remaining colors to the next LED. At the end of the line, our last LED will read the final RGB set and it has nothing left over to pass along.
Another way to visualize this is to imagine you have a bunch of different colored index cards. The Arduino creates a pile of the cards, where the top color is the desired color for the nearest LED, and the bottom color is the farthest away. The pile of cards is passed down the line of LEDS. As each LED gets the stack, they remove the top card, turn on their light to match that color, and pass the remaining colors down the stack.
We’re relying on the Pololu library to help us out with a lot of the low level communication here. By using this code library, we’re able to avoid a lot of the low level digital communication detail and focus on just making the LED strip do what we want. Of course, this code is open source and there’s nothing stopping you from taking a peek.