ArduinoArduino Projects

WS2811 Addressable RGB LED Strip with Arduino Code

Arduino and Addressable Led Strip(WS2811)

WS2811 Addressable led Strip

In this article, I will explain in detail how to use a Programmable and Addressable LED (WS2811 Addressable led strip) with Arduino. The serial Addressable LEDs are LEDs that can be expanded by connecting as many identical serial LEDs as possible, as long as the current allows. Among them, tape-shaped Addressable LEDs are often used. You can cut it to any length and use it for billboards, home decor, Christmas, and small projects. You can easily control the color and brightness from the Arduino using the library. So in this article, you will learn how to control the WS2811 addressable led strip.




What is a serial Addressable LED(WS2811)?

The serial Addressable LED was originally developed by WorldSemi in China and is called “NeoPixel“. Neo Pixel’s serial Addressable LEDs can be purchased individually, but it is convenient to have them in the form of a tape or in a matrix.

In particular, the tape-shaped Addressable serial LED can be cut to the desired length with scissors. The surface is coated with a soft transparent resin, and the back side is affixed with double-sided tape.

Development environment

The development environment for the experiments conducted in this article is as follows.

item version
Arduino device Arduino Nano
Serial LED Strip 5m/150 5050 RGB LEDs WS2811 LED Strip, Programmable and Addressable, IP67 Tube Waterproof 12V 30LEDs/m
Arduino IDE 1.8.10



Amazon Product links:

WS2811 LED Strip

Arduino Nano

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

You can also purchase the WS2811 addressable led strip from sunfounder the purchase link is given below

WS2811 LED Strip SunFounder

WS2811 Addressable LED Strip:

WS2811 Addressable led Strip

This is a 5 meters long, Programmable and Addressable, IP67 Tube Waterproof, 12V WS2811 RGB Led Strip. This RGB Led strip has a total of 150 Addressable LEDs; 30 LEDs/meter.  Each and every Led in this strip can be individually controlled and animated using any controller board.



Parameters of WS2811 LED Strip:

Product Model: BTF-5050RGB3T-2811-12V
Color: full color
Working voltage: DC12V
Power: 7.2W/M
LED number/m: 30 LEDs/M
IC model: WS2811
Number of IC per meter: 10pcs
Waterproof level:IP67(casing waterproof)
Luminous angle: 120°
Wavelength: R: 620-630λ; G: 520-525λ; B: 465-470λ.
Light intensity: R: 500-600mcd; G: 900-1200mcd; B: 250-310mcd.
Luminous flux: R: 1.68lm; G: 3.2lm; 0.84lm.
Size specification: 5000x10mm
Weight/roll: 320g

How Addressable LEDs Work

Here, I would like to explain the mechanism of the serial LED simply.

Serial Addressable LED structure

WS2811 Addressable led Strip

If you look closely at the Addressable LED, you will see an embedded IC chip like the one in the picture. This makes it possible to receive data sent from Arduino etc. and turn on the RGB colors of red, green, and blue.

Dout in the figure is connected to Din of the next WS2811 Addressable LED. As mentioned at the beginning, we connect several Addressable LEDs like a daisy chain. In addition, each LED can be independently changed in color and brightness.

There are different types of addressable LED strips available in the market the one I have purchased is the ws2811 led Strip. in this model, the ic chip has been mounted between three LEDs but in some models, this chip has been mounted after every single led. Therefore in ws2811 led strip, three LEDs count as one led.

Serial LED Arduino
VDD 5V
VSS GND
Din digital pin
Dout Din of next Addressable LED



Signal flow of Addressable LED(WS2811)

When one Addressable LED receives the data sent from DIN, only the top data is extracted and the rest of the data is passed from DOUT to another WS2811 Addressable LED. Each piece of data contains information about the brightness of the red, green, and blue LEDs, based on which each WS2811 Addressable LED is lit.

If the data is empty, it will not reach the Addressable LED beyond. Therefore, it is necessary to create data in advance for the number of WS2811 Addressable LEDs that you want to control. However, this time we will use the Neo Pixel library provided by Adafruit, so there is almost no difficult programming work, so don’t worry.




WS2811 LED Strip with Arduino:

The wiring between the WS2811 Addressable LED Strip and Arduino nano is shown below.

WS2811 Addressable led Strip

Digital pin D5 is connected to the DIN of the WS2811 Addressable LED strip, but of course, you can use any other pin. The Addressable LED operates with 5V voltage, but if possible, prepare a separate power supply instead of supplying power from the Arduino. This is because the current from the Arduino is not enough when trying to control dozens of LEDs. However, connect the GND with the Arduino.

as, in the circuit diagram I used the separated power supply, the WS2811 Addressable LEDs are connected in a daisy chain, but when using a WS2811 Addressable led strip, it is already wired in a daisy chain, so you only need to connect one Arduino digital pin to the DIN terminal at the end of the Strip…



How to Install Neo Pixel library:

Install the NeoPixel library released by Adafruit so that you can easily control the WS2811 Addressable LED Strip using Arduino.

In the Arduino IDE menu, open Sketch → Include Library → Manage Libraries → Library Manager.

So search for “neopixel” and install the Adafruit NeoPixel / Arduino library for controlling single-wire-based LED pixels and strip.

WS2811 Addressable led Strip

WS2811 Addressable led Strip



WS2811 Addressable Led Strip program example

From here, we will actually control the WS2811 Addressable LED Strip using Arduino.

Example: How to turn on only one WS2811 Addressable LED

In this example, I am going to show you how to turn on only one led of the  WS2811 Addressable LED Strip. As I told you above the model of the led strip that I am using is counts three LEDs as one because the ic chip is mounted between three LEDs but in most led strip models this chip is mounted after every single led. The program is as follows.

#include <Adafruit_NeoPixel.h>

const int DIN_PIN = 5; // D5

const int LED_COUNT = 150;

Adafruit_NeoPixel pixels(LED_COUNT, DIN_PIN, NEO_GRB + NEO_KHZ800);

void setup() { 

pixels.begin();

void loop() {

  pixels.clear(); 

pixels.setPixelColor(0, pixels.Color(128, 0, 0)); 

pixels.show();

}

Output:

WS2811 Addressable led Strip

Program Explanation:

First, I initialize the variable for the digital pin signal and LEDs

const int DIN_PIN = 5;

const int LED_COUNT = 150;

then I initialize the adafruit library class and pass the variables and library built-in functions as an arguments

Adafruit_NeoPixel pixels(LED_COUNT, DIN_PIN, NEO_GRB + NEO_KHZ800);

Set the correct number of Addressable LEDs to control. Note that you need to change NEO_GRB + NEO_KHZ800 for other Addressable LED strip models.

Then I used  

pixels.clear() 

to resets all Addressable LEDs and turns off any that are lit. 

To change the color of the Addressable LED, specify the number and color of the Addressable LED you want to control like 

pixels.setPixelColor(0, pixels.Color(128, 0, 0)).

sets the brightness from 0 to 255 in the order red, green, and blue. The higher the number, the brighter it will be, but the serial LED is very bright, so even a small number will look good.



Example: How to Change the color of the WS2811 Addressable LED Strip from red to green to blue

Now, let’s make some changes inside the loop function of the previous program as follows. The color of the WS2811 Addressable LED Strip changes in the order of red → green → blue.

void loop() {

  pixels.clear();

  pixels.setPixelColor(0, pixels.Color(128, 0, 0)); // red

  pixels.show();

  delay(1000);

  pixels.clear();

  pixels.setPixelColor(0, pixels.Color(0, 128, 0)); // green

  pixels.show();

  delay(1000);

  pixels.clear();

  pixels.setPixelColor(0, pixels.Color(0, 0, 128)); // blue

  pixels.show();

  delay(1000);

}

output:




Example: How to create Sequential lighting of 150 Addressable LEDs using Arduino

Now let’s turn on 150 Addressable LEDs in order. Let’s change the inside of the loop function as follows. It’s interesting that the light moves like a living thing.

void loop() {

  for(int i=0; i<LED_COUNT; i++) {

    pixels.clear();

    pixels.setPixelColor(i, pixels.Color(0, 0, 128)); // red

    pixels.show();

    delay(10);

  }

}

output:



Example: How to create rainbow animation with a WS2811 LED Strip using Arduino:

Finally, let’s make a very cool rainbow animation with WS2811 Addressable LED Strip. It may feel a little difficult because it uses C language arrays, but please get used to it little by little.

#include <Adafruit_NeoPixel.h>

const int DIN_PIN = 5; // D5

const int LED_COUNT = 150; // numbers of leds

Adafruit_NeoPixel pixels(LED_COUNT, DIN_PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  pixels.begin();

}

uint32_t red = pixels.Color(128, 0, 0);

uint32_t orange = pixels.Color(128, 82, 0);

uint32_t yellow = pixels.Color(128, 128, 0);

uint32_t green = pixels.Color(0, 128, 0);

uint32_t cyan = pixels.Color(0, 128, 128);

uint32_t blue = pixels.Color(0, 0, 128);

uint32_t purple = pixels.Color(128, 0, 128);

uint32_t rainbow_color[] = {red, orange, yellow, green, cyan, blue, purple};

int rainbow_index[] = {6, 5, 4, 3, 2, 1, 0};

void loop() {

  for(int i = 0; i < LED_COUNT; i++) {   

    pixels.clear();   

    for(int j = 0; j < 7; j++) {

      rainbow_index[j] = i + 6 – j;

      if(rainbow_index[j] >= LED_COUNT) rainbow_index[j] -= LED_COUNT;

      pixels.setPixelColor(rainbow_index[j], rainbow_color[j]);

    }

    pixels.show();

    delay(20);

  }

}

output:

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button