LED Strip
Introduction
Section titled âIntroductionâBefore thinking about the hardware or the software needed to light-up a LED strip, itâs mandatory to talk about the different driver chips used to control the LEDs.
WS2811 VS WS2812
Section titled âWS2811 VS WS2812âThe main differences are summarized into different categories:
- Power:
WS2811
LED chip needs a voltage of12V
to work, whileWS2812
chip only uses5V
. - LEDs Controlled:
WS2811
actually do not control one LED, but instead it controls a cluster of3
LEDs together.WS2812
can control1
LED each.
Common Software Setup
Section titled âCommon Software SetupâTo avoid repeating myself later on, letâs describe the different environments youâll need to set up to get everything up and running.
Software Setup for Arduino
Section titled âSoftware Setup for ArduinoâArduino IDE is the best choice to program the Arduino board within its C-like language. If are skilled enough, you could also use the powerful command line interface Arduino CLI.
Please refer to the official Getting Started guide to install the IDE on the OS you prefer.
Software Setup for Python
Section titled âSoftware Setup for PythonâOne of the best environments for Python programming (and definitely my favorite) is PyCharm by JetBrains. However, PyCharm is not really suitable for running python scripts from the Raspberry Pi board, since itâs very resource-consuming.
Some light-weight IDEs are:
- Visual Studio Code which is also available for Raspberry PI by following this guide
- Thonny which is installed by default on Raspberry Pi OS
- Mu
Hardware requirements & setup
Section titled âHardware requirements & setupâ- Arduino Uno board or any ArduinoUno-like board
- LED strip, suggested stores are:
470 Ohms
resistor100 ÂľF
capacitor- Hook-up wires of different colors
- Breadboard
- 12V power supply if using a strip controlled by
WS2811
chip
FastLED
Section titled âFastLEDâThe common code for all the following effects made with FastLED
library is:
#include "FastLED.h"// digital output pin of the board#define PIN 6// number of LEDs of the strip#define NUM_LEDS 100
CRGB leds[NUM_LEDS];
// increase this value to slow down the effectunsigned short int delayTime = 5;
void setup() { FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);}
// void loop and effect function
void showStrip() { FastLED.show();}
void setPixel(int pixelNumber, byte red, byte green, byte blue) { leds[pixelNumber].r = red; leds[pixelNumber].g = green; leds[pixelNumber].b = blue;}
void setAll(byte red, byte green, byte blue) { for (int i = 0; i < NUM_LEDS; i++) { setPixel(i, red, green, blue); } showStrip();}
NeoPixel
Section titled âNeoPixelâThe common code for all the following effects made with NeoPixel
library is:
#include <Adafruit_NeoPixel.h>
// digital output pin of the board#define PIN 6// number of LEDs of the strip#define NUM_LEDS 100
// Parameter 1 = number of pixels in strip// Parameter 2 = pin number (most are valid)// Parameter 3 = pixel type flags, add together as needed:// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() { // initialize the strip strip.begin(); // initialize all pixels to 'off' strip.show();}
// void loop and effect function
void showStrip() { strip.show();}
void setPixel(int pixelNumber, byte red, byte green, byte blue) { strip.setPixelColor(pixelNumber, strip.Color(red, green, blue));}
void setAll(byte red, byte green, byte blue) { for (int i = 0; i < NUM_LEDS; i++) { setPixel(i, red, green, blue); } showStrip();}
Effects
Section titled âEffectsâYou can take all the sketches from:
led-strip
directory fromarduino-projects
GitLab repository- Raspberry Pi LED Strip Project
Jump to effects
folder to see the list of effects in both the repositories.
Fill free to send me a pull request if you have any suggestion for the effects I could add or improve.
Here is the list:
- BouncingBalls This effect looks best with the LED strip vertical, and shows one or more bouncing balls in a given color.
- BouncingRGBFade
This effect uses a sequence of fixed colorsâ list for all LEDs: red, green and blue. It slowly increases brightness and when the maximum brightness has been reached, it starts decreasing the brightness again until the LEDs are all OFF.
- ChasingLight
A backhoe of LEDs moves forward and then downward the strip. Each LED is colored with a different composition of the red, green and blue components.
- ColorWipe
You can define different colors that will fill the whole strip, from the first to the last. When a color lights-up all the LEDs, the next color starts over the strip to replace the previous color. You can also allow the color to fill the strip form the last to the fist element using
reverseColorWipe
method.
- FadeInFadeOut-ColorAndBrightness
It fades in and out both color and brightness of the colors you want.
- FadeInFadeOut-ColorWithoutBrightness
It fades in and out color and fakes the fade of the brightness. It is very similar to the effect above.
- Fire
This effect is adapted from an example from
FastLED
, which is adapted from work done by Mark Kriegsman (called âFire2012â). It looks awesome when using diffuse light!
- MeteorRain
This effect looks better with the whole strip placed in vertical position. It creates a meteor that runs through the sky with some randomness LEDs switched on for the tail.
- MultiColor-BouncingBalls
This is a more complex variant of the Bouncing Balls effect. Instead of just one color, it allows the use of multiple colors. This makes the function call a little more complex, since it works for any number of balls youâd like set. To pass the color for each ball you will have to define a multidimensional array filled with the RGB backhoe of each balls.
- NewKITT
This effect follows this pattern:
<---------
--------->
----><----
<---------
--------->
<---------
----><----
<-------->
Inspiration for this effect was taken from
instructables
â article The KITT-duino DIY Larson Scanner.
- RainbowCycle
Fills all the LDEs with different shades of rainbow colors and slowly moves the colors from the start to the end of the strip. It also looks good on a LED matrix like this Flexible 8x8 NeoPixel RGB LED Matrix from adafruit.com.
- RandomColorTwinkle
This is a variation on the Twinkle effect. The only difference is that the colors are now randomly generated.
- RunningLights
This effect makes multiple groups of LEDs chase each other.
- Scanner
This effect mimics the LED of a scanner that runs forward (and downward) the length of the document to scan.
- Strobe
This effect turn the strip in a stroboscopic light. Please Note:
Strobe
effect could lead to epilepsy phenomena in photosensitive subjects.
- TheatreChase
With this effect LEDs are chasing each other like what youâd see in an old Theatre.
- TheatreChaseRainbow
This effect combines RainbowCycle and TheatreChase.
- Twinkle
This effect will blink one or more LEDs in a given color.
Conclusion
Section titled âConclusionâHere we are, at the end of this long blog post. Here are some ideas where you could use those effects:
- smart home with adaptive lights
- alarm system
- notification system
- party lights
Hope you enjoyed this post as much I loved write it. It does not matter weather you prefer to use Arduino or Raspberry Pi or any other board to light up a LED strip.
Keep in mind that there is always a way to do what you want to do.
Documentation
Section titled âDocumentationâSome useful links: