WS2812B Ambient Light For TV Using Arduino

Nowadays, LED is a huge decoration factor in our daily life. It has not only made our life decorative but also reduced our electricity consumption. By keeping this factor in mind, here we are going to use a WS2812B RGB Addressable LED strip for our project Ambient Light for TV. RGB LED is a multifunctional light that can be used for various electronics projects, photography, filmmaking, 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 the Ambient Light Application to control the WS2812B LED strip for android TV.

Must Read DIY Ambient Light For Computer


DIY Ambient Light

Circuit Diagram

Ambient Light Circuit Diagram

Components Required

  • Arduino Nano
  • WS2812B Addressable LED Strip
  • 5V/3A Decent Power Supply

About Parts for Ambient Light


For the compact build, I choose Arduino Nano despite Arduino UNO. Arduino Nano is a small, flexible microcontroller board using an Atmega328p chip. It can also use as a substitute for UNO. All the functions are the same in these two boards. The size of its PCB is 18×45 mm. The clock speed is 16Mhz. Its input voltage is 5-12V. There are 30 pins including power pins, data pins, analog pins, and serial pins on this board.

WS2812B Addressable LED Strip

The WS2812B 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 inner connection. It has four terminals inside the LED package i.e VDD, VSS, DIN and DOUT. VSS is used to power up the LED and VDD is connected to the ground. DIN control the inputted data signal as well as DOUT through the received data to the next WS2812B controller chip respectively.

Calculation of Current Required for Drive The LED Strip

To proceed with constructing 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. And if we individually take 50 LEDs then the current is 3A. This is more than an Arduino can supply.

So the best way to power up the whole system is an external 5V/3A pure DC power supply that can provide enough current.

Process of Setting Up Ambient Light On The TV

Now come to the LED strip part. There you need to attach the LED strip from the left-bottom side to the left-top side, then the right-top side to the right-bottom side. We do this pattern because in the application this is the default pattern. But you can change it as your wish. Just need to define the pattern in the application that’s it.

After that connect the data pin of the LED strip with the digital pin (D4) of the Arduino and as well as VCC And ground respectively.

Attaching ws2812b led strip behind the tv

Ambient Light Application Setup for TV

First, we need to download and install the “Ambient Light Application for Android” from the playstore. It costs around rupees 240 or 3 dollars. After installation, open the application on the TV and go to settings.

  • There you need to define the total number of horizontal LEDs (choose any one part i.e., top or bottom). Similarly, specify the total number of vertical LEDs.
  • Keep the bottom gap value to zero.
  • Set LED strip direction to CW (Clock Wise)
  • Define the first LED offset to (-) of the total number of vertical LEDs.

And leave the rest of the settings as it is. For my purpose, this is the setting.

settings page of ambient light setup

Lastly back to the homescreen and select “Screen Capturing Mode” out of three modes.

Arduino Code

To compile this code you need to install this library first “FastLED.h“.

#include "FastLED.h"#define INITIAL_LED_TEST_ENABLED true#define INITIAL_LED_TEST_BRIGHTNESS 16  // Change the brightness between 0 to 255#define INITIAL_LED_TEST_TIME_MS 250// We will use a maximum of 300 leds#define MAX_LEDS 141   // Number of leds in your strip// type of your led controller#define LED_TYPE WS2812B // DATA_PIN#define LED_PINS 6        // 3 wire leds#define COLOR_ORDER GRB  // colororder of the stripe, set RGB in hyperion#define OFF_TIMEOUT 6000    // ms to switch off after no data was received, set 0 to deactivate#define BRIGHTNESS 255     // max brightness 0 to 255#define DITHER_MODE BINARY_DITHER    // BINARY_DITHER or DISABLE_DITHER#define COLOR_TEMPERATURE CRGB(255,255,255) // RGB value describing the color temperature#define COLOR_CORRECTION  TypicalLEDStrip   // predefined fastled color correction#define BAUD_RATE 115200      // use 115200 baudrate for ftdi based boards// Adalight sends a "Magic Word" before sending the pixel datauint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;unsigned long endTime;// Define the array of ledsCRGB leds[MAX_LEDS];// set color to all ledsvoid showColor(const CRGB& led) {  #if MAX_LEDS > 1  LEDS.showColor(led);  #endif}// switch of ledsvoid switchOff() {  #if MAX_LEDS > 1  memset(leds, 0, MAX_LEDS * sizeof(struct CRGB));;  #endif}// function to check if serial data is availablebool checkIncommingData() {  boolean dataAvailable = true;  while (!Serial.available())   {    if ( OFF_TIMEOUT > 0 && endTime < millis())     {      switchOff();      dataAvailable = false;      endTime = millis() + OFF_TIMEOUT;    }  }  return dataAvailable;}// main function that setups and runs the codevoid setup() {  Serial.begin(BAUD_RATE);  Serial.print("Ada\n"); // Send "Magic Word" string to host  int ledCount = MAX_LEDS;  #if MAX_LEDS > 1    FastLED.addLeds<LED_TYPE, LED_PINS, COLOR_ORDER>(leds, ledCount);  #endif    // color adjustments  FastLED.setBrightness ( BRIGHTNESS );  FastLED.setTemperature( COLOR_TEMPERATURE );  FastLED.setCorrection ( COLOR_CORRECTION );  FastLED.setDither     ( DITHER_MODE );  // initial RGB flash  #if INITIAL_LED_TEST_ENABLED == true  for (int v=0;v<INITIAL_LED_TEST_BRIGHTNESS;v++)  {    showColor(CRGB(255,0,0));      delay(INITIAL_LED_TEST_TIME_MS/2/INITIAL_LED_TEST_BRIGHTNESS);  }  for (int v=0;v<INITIAL_LED_TEST_BRIGHTNESS;v++)  {    showColor(CRGB(0,255,0));      delay(INITIAL_LED_TEST_TIME_MS/2/INITIAL_LED_TEST_BRIGHTNESS);  }  for (int v=0;v<INITIAL_LED_TEST_BRIGHTNESS;v++)  {    showColor(CRGB(0,0,255));      delay(INITIAL_LED_TEST_TIME_MS/2/INITIAL_LED_TEST_BRIGHTNESS);  }  #endif  showColor(CRGB(0, 0, 0));  boolean transmissionSuccess;  unsigned long sum_r, sum_g, sum_b;  // loop() is avoided as even that small bit of function overhead  for(;;)   {    // wait for first byte of Magic Word    for (i = 0; i < sizeof prefix; ++i)     {      // If next byte is not in Magic Word, the start over      if (!checkIncommingData() || prefix[i] !=       {        i = 0;      }    }    if (!checkIncommingData()) continue;    hi =;    if (!checkIncommingData()) continue;    lo =;    if (!checkIncommingData()) continue;    chk =;    // if checksum does not match go back to wait    if (chk != (hi ^ lo ^ 0x55)) continue;    int num_leds = min ( MAX_LEDS, (hi<<8) + lo + 1 );	memset(leds, 0, num_leds * sizeof(struct CRGB));    transmissionSuccess = true;    sum_r = 0;    sum_g = 0;    sum_b = 0;    // read the transmission data and set LED values    for (int idx = 0; idx < num_leds; idx++)     {      byte r, g, b;      if (!checkIncommingData())       {        transmissionSuccess = false;        break;      }      r =;      if (!checkIncommingData())       {        transmissionSuccess = false;        break;      }      g =;      if (!checkIncommingData())       {        transmissionSuccess = false;        break;      }      b =;      leds[idx].r = r;      leds[idx].g = g;      leds[idx].b = b;    }    // shows new values    if (transmissionSuccess)     {      endTime = millis() + OFF_TIMEOUT;      #if MAX_LEDS > 1;      #endif    }  }} // end of setupvoid loop() {}

Post a Comment

Previous Post Next Post