WS2812B LED Strip

WS2812B LED Strip Control Experiment

Introduction

WS2812B LED strips are individually addressable RGB LEDs that can produce stunning lighting effects. Each LED in the strip has a built-in driver IC, allowing precise control of colors and brightness using a single data pin. This tutorial demonstrates how to use Arduino to control a WS2812B LED strip.

Components Needed

Circuit Setup

  1. Connect the +5V pin of the LED strip to the 5V output of the power supply.
  2. Connect the GND pin of the LED strip to the power supply GND and Arduino GND.
  3. Add a 1000 µF capacitor across the power supply (between +5V and GND) to protect the LEDs from power surges.
  4. Connect the DIN (data input) pin of the LED strip to a digital pin on the Arduino (e.g., pin 6) via a 330Ω resistor.

Note: Ensure the ground of the LED strip, power supply, and Arduino are connected together.

Code for WS2812B LED Strip

Upload the following code to your Arduino to control the LED strip:


// Include the FastLED library
#include 

// Define the number of LEDs and the pin used
#define NUM_LEDS 30 // Adjust to match your LED strip
#define DATA_PIN 6

// Create a FastLED array to hold LED data
CRGB leds[NUM_LEDS];

void setup() {
    // Initialize the FastLED library
    FastLED.addLeds(leds, NUM_LEDS);
}

void loop() {
    // Set all LEDs to red
    for (int i = 0; i < NUM_LEDS; i++) {
        leds[i] = CRGB::Red;
    }
    FastLED.show(); // Update the LEDs
    delay(1000);

    // Set all LEDs to green
    for (int i = 0; i < NUM_LEDS; i++) {
        leds[i] = CRGB::Green;
    }
    FastLED.show();
    delay(1000);

    // Set all LEDs to blue
    for (int i = 0; i < NUM_LEDS; i++) {
        leds[i] = CRGB::Blue;
    }
    FastLED.show();
    delay(1000);

    // Rainbow effect
    for (int i = 0; i < NUM_LEDS; i++) {
        leds[i] = CHSV((i * 255) / NUM_LEDS, 255, 255);
    }
    FastLED.show();
    delay(1000);
}
            

Explanation

Power Considerations

Each LED in a WS2812B strip can draw up to 60 mA at full brightness (white color). For larger strips:

Troubleshooting