Controlling WS2812b Leds with ESP8266 | FastLed | Sliding Pot

Interfacing WS2812b with esp8266 using FastLed

In this experiment we will learn about WS2812b leds and try to control them using a siding potentiometer. 




Each led in the strip as a unique address allowing for individual control and can display wide range of colours including RGB and white with varying brightness. The strip works at 5V and consumes 50mA per led.It has a data transfer rate of 800Kbps. It requires only one data pin from micro controller making it versatile and easy plugin to projects. 

We will use FastLed library for controlling the led strip.


Now lets talk about siding potentiometer. 


This is a 10K ohm resistor pot with a sliding knob to control resistance. It works on 3.3v and 5v and outputs a voltage between Gnd and Vcc which can be treated as a analog signal. This signal can then be fed to ADC for digital conversion. We will connect  output terminal to ESP A0 pin to extract digital value and use it to control number of leds.

Circuit Diagram




Connections


Power module        ESP8266        Potentiometer        WS2812b strip
        5V                        Vin                                                   5V
        Gnd                     Gnd                    Gnd                       Gnd    
                                      A0                    outA
                                     D5                      Din

Code


#include <FastLED.h>

#define NUM_LEDS 11
#define DATA_PIN D5

CRGB leds[NUM_LEDS];

void setup() { 
    FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
    FastLED.setBrightness(64);
}

void loop() { 
    int noOfLeds = analogRead(A0)/100 + 1;
    delay(20);
    CRGB colors[8] = { CRGB::Orchid, CRGB::Aqua, CRGB::Coral, CRGB::DeepPink, CRGB::Lime, CRGB::Navy, CRGB::Plum, CRGB::YellowGreen };
    for(int j = 0; j< 8; j++ ) {
      for( int i = 0; i < noOfLeds; ++i) {
          leds[i] = colors[j];
      }
      for( int i = noOfLeds; i < NUM_LEDS; ++i) {
          leds[i] = CRGB::Black;
      }
      FastLED.show();
      delay(200);
    }
}


This potentiometer when slided gives varying voltage , we will use it to lit Leds.





Troubleshooting
1. Ensure the ground of ESP and LED strip are connected. If you are working with ESP connected to CPU it might alter the voltage and leds may not be lit correctly. I would recommend removing esp completely from CPU while testing.
2. Ensure that power supply has sufficient current rating to lit leds (50mA for each Led). 

Comments

Popular posts from this blog

Microphone Sound Sensor explained | HW-484 | Interfacing with ESP 8266

Using ESP 01 in Access Point (AP) mode to control ESP relay switch | ESP wifi tutorial | Part - 1

[Experiment] DIY Robotic 2 wheel drive car using L298N motor driver and NodeMCU | ESP 8266