WS2811 RGB Led Strip with Arduino,FastledWS2811 12V
Arduino fastled Color Palette Tutorial using WS2811 RGB Led Strip
Table of Contents
WS2811 RGB Led Strip:
WS2811 RGB Led Strip with Arduino, Fastled WS2811 12V– Recently, I got a 5 meters long, Programmable and Addressable, IP67 Tube Waterproof, 12V WS2811 RGB Led Strip from SunFounder for only 23.99 dollars with free shipping. This RGB Led strip has a total of 150 Addressable LEDs; 30 LEDs/meter. Each and every Led in this strip can be individually programmed using a microcontroller board like Arduino, ESP8266, ESP32 WiFi + Bluetooth Module, STM32, etc, using only one pin on your controller board.
Since this is my first time using the WS2811 Led strip, so first I am going to start with the Arduino and then later I will use this LED strip with other controller boards as well. I will make a complete series covering, how to control the WS2811 Led strip using Android Bluetooth Application, IR Remote controller, WiFi, Long Range Radio transceiver modules like Lora, and NRF24L01, etc. So, consider subscribing if you don’t want to miss any of my upcoming projects.
Anyway, as usual, before I am going to share with you its technical specifications, It’s interfacing with Arduino, Library installation, and different programs. First, I am going to share with you the final test results and afterward, I will explain everything else.
I am using my 4S lithium Ion Battery pack to power up the Entire Led strip and the Arduino board. You can read my previous article if you want to make the same Lithium Ion Battery pack or you can use a 12V adaptor.
I have already uploaded the Example number 1 code. So, let’s go ahead and power up the Led Strip and Arduino Board.
I successfully tested more than 10 different projects. I didn’t had to write even a single line of code except changing the number of the LEDs in the strip. The Library itself consists of so many example codes which can also be modified.
If you don’t like any of those readymade LEDs effects, you can also try the Adafruit library or the pixels library or you can write your own unique code and make some cool animations. Anyway, now I am going to explain all the other important things, so, without any further delay, let’s get started!!!
Amazon Links:
Arduino Nano USB-C Type (Recommended)
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
WS2811 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 animated using a controller board like Arduino, ESP8266, ESP32 WiFi + Bluetooth Module, STM32, etc, using only pin on your controller board.
Every 3 LEDs can be cut without damaging the rest of the strip to help you meet different size needs.
The Operating voltage is 12V and its 7.2Watts/meter and the chip model is WS2811. There are 10 WS2811 ICs per meter. The Entire Led strip is covered with a Silicone tube which makes it IP67 Waterproof.
This LED strip has got connectors on both the ends, this way multiple LED strips can be connected without any issues.The RED wires are 12v wires, the green wire is the Din wire, and the White wires are the ground wires.
Parameters:
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
Wide Application
It can be used to make led screen, led wall, advertising boards and widely applied to hotel, KTV, bars, Outdoor advertising signs, wedding party lighting, home and car decoration, city skyline, building outline and so on.
WS2811 LED Strip with Arduino:
The data in or DIN pin on the WS2811 LED strip is connected with the D5 pin on the Arduino. And the +12V and GND pins are connected with the 12V external power supply. In my case I am using a 4S lithium Ion Battery pack. And I am using a 5V regulated power supply to power up the Arduino board. As you can see the Output and ground legs of the 7805 voltage regulator are connected with the VIN and GND pins of the Arduino.
For the easy interfacing, I also soldered this DC Female power jack with the Red and White wires and now I can easily connect a power supply.
You can download the Gerber files of the Arduino Nano Development board from PCBWay.
Finally, I connected everything as per the circuit diagram.
And now let’s take a look at the programming.
Required Library:
As usual, before you start the programming, first of all, make sure you install the FastLED library. To install this library simply go to the Sketch Menu, then to Include Library, and click on the Manage Libraries, and Search for the fastled.
As you can see I have already installed this library.
WS2811 LED Strip Arduino Code:
After installing the library, you can start with the readymade example codes.
As you can see there are more than 20 example codes. You can check these one by one and you will get the idea how the code works. Let’s go ahead and open one example code.
ColorPalette Example Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
#include <FastLED.h> #define LED_PIN 5 #define NUM_LEDS 150 #define BRIGHTNESS 250 #define LED_TYPE WS2811 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; #define UPDATES_PER_SECOND 100 // This example shows several ways to set up and use 'palettes' of colors // with FastLED. // // These compact palettes provide an easy way to re-colorize your // animation on the fly, quickly, easily, and with low overhead. // // USING palettes is MUCH simpler in practice than in theory, so first just // run this sketch, and watch the pretty lights as you then read through // the code. Although this sketch has eight (or more) different color schemes, // the entire sketch compiles down to about 6.5K on AVR. // // FastLED provides a few pre-configured color palettes, and makes it // extremely easy to make up your own color schemes with palettes. // // Some notes on the more abstract 'theory and practice' of // FastLED compact palettes are at the bottom of this file. CRGBPalette16 currentPalette; TBlendType currentBlending; extern CRGBPalette16 myRedWhiteBluePalette; extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; void setup() { delay( 3000 ); // power-up safety delay FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } void loop() { ChangePalettePeriodically(); static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion speed */ FillLEDsFromPaletteColors( startIndex); FastLED.show(); FastLED.delay(1000 / UPDATES_PER_SECOND); } void FillLEDsFromPaletteColors( uint8_t colorIndex) { uint8_t brightness = 255; for( int i = 0; i < NUM_LEDS; ++i) { leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); colorIndex += 3; } } // There are several different palettes of colors demonstrated here. // // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p, // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p. // // Additionally, you can manually define your own color palettes, or you can write // code that creates color palettes on the fly. All are shown here. void ChangePalettePeriodically() { uint8_t secondHand = (millis() / 1000) % 60; static uint8_t lastSecond = 99; if( lastSecond != secondHand) { lastSecond = secondHand; if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; } if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; } if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; } if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; } if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; } if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; } if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; } if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; } if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } } } // This function fills the palette with totally random colors. void SetupTotallyRandomPalette() { for( int i = 0; i < 16; ++i) { currentPalette[i] = CHSV( random8(), 255, random8()); } } // This function sets up a palette of black and white stripes, // using code. Since the palette is effectively an array of // sixteen CRGB colors, the various fill_* functions can be used // to set them up. void SetupBlackAndWhiteStripedPalette() { // 'black out' all 16 palette entries... fill_solid( currentPalette, 16, CRGB::Black); // and set every fourth one to white. currentPalette[0] = CRGB::White; currentPalette[4] = CRGB::White; currentPalette[8] = CRGB::White; currentPalette[12] = CRGB::White; } // This function sets up a palette of purple and green stripes. void SetupPurpleAndGreenPalette() { CRGB purple = CHSV( HUE_PURPLE, 255, 255); CRGB green = CHSV( HUE_GREEN, 255, 255); CRGB black = CRGB::Black; currentPalette = CRGBPalette16( green, green, black, black, purple, purple, black, black, green, green, black, black, purple, purple, black, black ); } // This example shows how to set up a static color palette // which is stored in PROGMEM (flash), which is almost always more // plentiful than RAM. A static PROGMEM palette like this // takes up 64 bytes of flash. const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM = { CRGB::Red, CRGB::Gray, // 'white' is too bright compared to red and blue CRGB::Blue, CRGB::Black, CRGB::Red, CRGB::Gray, CRGB::Blue, CRGB::Black, CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray, CRGB::Blue, CRGB::Blue, CRGB::Black, CRGB::Black }; // Additional notes on FastLED compact palettes: // // Normally, in computer graphics, the palette (or "color lookup table") // has 256 entries, each containing a specific 24-bit RGB color. You can then // index into the color palette using a simple 8-bit (one byte) value. // A 256-entry color palette takes up 768 bytes of RAM, which on Arduino // is quite possibly "too many" bytes. // // FastLED does offer traditional 256-element palettes, for setups that // can afford the 768-byte cost in RAM. // // However, FastLED also offers a compact alternative. FastLED offers // palettes that store 16 distinct entries, but can be accessed AS IF // they actually have 256 entries; this is accomplished by interpolating // between the 16 explicit entries to create fifteen intermediate palette // entries between each pair. // // So for example, if you set the first two explicit entries of a compact // palette to Green (0,255,0) and Blue (0,0,255), and then retrieved // the first sixteen entries from the virtual palette (of 256), you'd get // Green, followed by a smooth gradient from green-to-blue, and then Blue. |
About the code:
Once you open the program. Enter the pin number which is connected with the Data in pin on the LED strip, Next, enter the number of LEDs you want to control. Specify the brightness and update the chip type if incase your LED strip has a different chip. Make same changes in all the other example codes. If you want to see different example codes in action then you should watch my video.