DIY WS2812B Addressable LED – Controllable Using Arduino

In nowadays, LED is a huge decoration factor in our daily life. It has not only made our life simpler but also reduced our electricity consumption. By keeping this factor in mind, here we are going to discuss WS2812B RGB Addressable LED for this present project. RGB LED is a multifunctional light that can be used for various electronics projects, photography, film making, gaming decoration, music VU meter and much more.

For this project, we are going to use the WS2812B RGB LED strip and an Arduino Nano to program and run the LED strip as the user’s choice. Here we use Prismatik software to control the addressable LED or via a push button.

Must Read RGB LED Chaser

WS2812B Addressable LED Strip

The WS2812B Arduino Addressable LED is a very cool LED light that contains a WS2812B LED controller IC and a 5050 RGB LED. The below image shows the WS2812B Addressable LED strip. It has four terminals inside the LED package i.e VDD, VSS, DIN and DOUT.

VDD is used to power up the LED and VSS is connected to the ground. DIN and DOUT control data input and output respectively.

To know more about WS2812B RGB LED Controller IC then check out this article WS2812B Configuration

How to Control RGB Addressable LED Using Arduino?

To proceed with the construction of the LED first, we need to know the voltage requirement of the single 5050 RGB LEDs. Each WS2812B LED pixel has three types of LEDs i.e Red (20 mA), Green (20 mA) and Blue (20 mA). So the total current requirement is 60mA i.e 1.2 A. This is more than an Arduino can supply.

So the best way to power up the whole system is an external 5V power source that can provide enough current.

Project

DIY WS2812B Addressable LED
DIY WS2812B Addressable LED

Circuit Diagrams

addressable led

Components Required

  • Arduino
  • WS2812B LED Strip
  • Wires
  • 5V Power Supply

Software Required For Addressable LED

To control this LED strip, we need PC software i.e. Prismatik software. It has many different types of effects like mood lamp, fire, screen grabbing, fading, etc. For installing this software first we need to double click on the Prismatik.exe file, then click Select Adalight→select serial port no→next→select Lightpack and next→then select no of LEDs in the top, bottom and centre then finish.

Arduino Code

#include "FastLED.h"
#define NUM_LEDS 60
#define DATA_PIN 3
#define serialRate 115200
uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
// Initialise LED-array
CRGB leds[NUM_LEDS];
void setup() {
  // Use NEOPIXEL to keep true colors
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  
  // Initial RGB flash
  LEDS.showColor(CRGB(255, 0, 0));
  delay(500);
  LEDS.showColor(CRGB(0, 255, 0));
  delay(500);
  LEDS.showColor(CRGB(0, 0, 255));
  delay(500);
  LEDS.showColor(CRGB(0, 0, 0));
  
  Serial.begin(serialRate);
  
  Serial.print("Ada\n");
}
void loop() 
{ 
  // Wait for first byte of Magic Word
  for(i = 0; i < sizeof prefix; ++i) 
  {
    waitLoop: while (!Serial.available()) ;;
    // Check next byte in Magic Word
    if(prefix[i] == Serial.read()) continue;
    // otherwise, start over
    i = 0;
    goto waitLoop;
  }
   
  while (!Serial.available()) ;;
  hi=Serial.read();
  while (!Serial.available()) ;;
  lo=Serial.read();
  while (!Serial.available()) ;;
  chk=Serial.read();
  
  if (chk != (hi ^ lo ^ 0x55)) 
  {
    i=0;
    goto waitLoop;
  }
  
  memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
  
  // Read the transmission data and set LED values
  
  for (uint8_t i = 0; i < NUM_LEDS; i++) 
  {
    byte r, g, b;    
    while(!Serial.available());
    r = Serial.read();
    while(!Serial.available());
    g = Serial.read();
    while(!Serial.available());
    b = Serial.read();
    leds[i].r = r;
    leds[i].g = g;
    leds[i].b = b;
  }
  
  FastLED.show();
}

RGB Addressable LED Using Arduino And Push Button

Next, I am going to show you how to control this RGB LED strip using a push button.

Circuit Diagram

DIY WS2812B Addressable LED

Components Required

  • Arduino
  • WS2812B LED Strip
  • Push Button
  • Wires
  • 5V Power Supply

Circuit Connection

The data pin connection of the Arduino is the same as the above. The only change is the analog pin to the push button. Connect the A0 pin of the Arduino to the one node of the push button and another node of the push button with the ground.

After that, we can change different effects via using a push button.

Arduino Code

#include <FastLED.h>
#include <Pushbutton.h>
#define LED_PIN     3
#define NUM_LEDS    60
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define BRIGHTNESS  255
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
CRGBPalette16 currentPalette;
TBlendType    currentBlending;
#define button1 A0
Pushbutton pbutton1(button1);
int mode=0;
void setup()
{
  Serial.begin(9600);
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(  BRIGHTNESS );
  currentPalette = RainbowColors_p;
  currentBlending = LINEARBLEND;
}
void fadeall()
{ 
  for(int i = 0; i < NUM_LEDS; i++) 
  { 
    leds[i].nscale8(250);
  }
}
void loop() 
{
  if(pbutton1.isPressed())
  {
    mode++;
    delay(1000);
  }
  if(mode==1)
  {
    for(int i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB(255, 30,0);
      FastLED.show();
    }
  }
  if(mode==2)
  {
    for(int i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB(0, 100,255);
      FastLED.show();
    }
  }
  if(mode==3)
  {
    for(int i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB(255, 0,100);
      FastLED.show();
    }
  }
  if(mode==4)
  {
    for(int i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB(255, 0, 0);
      FastLED.show();
    }
  }
  if(mode==5)
  {
    for(int i = 0; i < NUM_LEDS; i++){
      leds[i] = CRGB(0, 255,0);
      FastLED.show();
    }
  }
  if(mode==6)
  {
      static uint8_t hue = 0;
  for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(hue++, 255, 255);
    FastLED.show(); 
    fadeall();
    delay(10);
  }
  for(int i = (NUM_LEDS)-1; i >= 0; i--) {
    leds[i] = CHSV(hue++, 255, 255);
    FastLED.show();
    fadeall();
    delay(10);
  }
  }
  if(mode==7)
  {
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; 
    FillLEDsFromPaletteColors( startIndex);
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
  }
  if(mode==8)
  {
    FastLED.clear();
    FastLED.show();
    mode=mode-8;
  }
}
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;
    }
}

1 thought on “DIY WS2812B Addressable LED – Controllable Using Arduino”

  1. I have been surfing online for more than 3 hours today, but I by no means discovered any interesting article like yours. It is pretty price sufficient for me. In my view, if all site owners and bloggers made just the right content material as you did, the web will be much more useful than ever before.

    Reply

Leave a Comment