Table of Contents
This blog will guide you how to control WS2812B LED strip with Arduino. It covers properly powering and wiring the components, uploading code via the Arduino IDE, and bringing your LEDs to life with custom effects.
1. Materials Required
Power Supply
Output
- Voltage: DC 5V
- Current: Up to 40A
- Power Rating: 200W
Input
- Voltage Range: AC 110V/220V (dual input supported, switch-selectable)
Use in This Setup:
- Powers both the WS2812B LED strip and the Arduino UNO (via 5V/GND lines)
- Provides sufficient current for large numbers of LEDs
- Industrial-grade reliability and ventilation for heat dissipation
Arduino Board
Model: Arduino UNO R3 (ATmega328P-based)
Microcontroller: ATmega328P
Operating Voltage: 5V
Input Voltage (recommended): 7–12V (but here it’s powered directly via 5V pin from the PSU)
Digital I/O Pins: 14 (of which 6 can be used as PWM outputs)
Analog Input Pins: 6
Clock Speed: 16 MHz
Programming Interface: USB Type-B
Use in This Setup:
- Acts as the controller for sending digital data signals to the WS2812 strip
- Connected to the power supply through the 5V and GND pins (bypassing the onboard voltage regulator)
- Data output pin (e.g., D6 or D7) connects to the “DIN” of the WS2812 LED strip via the white wire
WS2812B LED Strip
Type: Individually addressable RGB LED strip with built-in WS2812 IC per LED
Voltage: 5V DC
Communication Protocol: Single-wire, 800kHz
Features: Integrated control chip, allows full color and brightness control per pixel
LED Density: 60 LEDs per meter
Accessories & Tools
- Connecting Wires: Use appropriate gauge, e.g., 18–22 AWG
- Logic-Level Shifter (Optional): Recommended if Arduino outputs 3.3V logic
2. Wiring Schematic
Here’s a schematic wiring diagram from LEDSuntech.
Note:
1. The current of the control board is <500mA;
2. The current of the LED strip is too large; please use an external power supply to power the LED strip.
3. The DC3.3/5V interface is the voltage output port of the control board, which cannot be connected to the power supply. Use the DC interface or VIN+GND to connect the power supply.
4. DC12V powers the LED strip, and the control board’s power supply range is DC3.3- 9V, so the control board and WS2812B LED strip are powered by DC12V.
5. The wiring of RGB is the same as that of RGBW, but the program cannot be shared.
6. RGB pixel points <500 points, RGBW pixel points <375 points, RGBWW <300 points; the more points, the lower the refresh rate.
3. Connection Diagram
Tips:
- Short, direct data wire from Arduino to DIN
- Secure terminal connections on the power supply
- Always disconnect power before rewiring
4. Code Upload
Software: Arduino IDE
Library Used: FastLED
LEDSuntech provides codes for a variety of light changing effects. If you have any questions, please feel free to contact our professional team of engineers.
#include
#define LED_PIN 19 // LED strip data pin
#define NUM_LEDS 80 // LED quantity
#define BRIGHTNESS 128 // Initial Brightness(0-255)
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB // Most WS2812 are GRB sequential
CRGB leds[NUM_LEDS];
// Effect Mode Enumeration
enum Effects {
EFFECT_FLOW,
EFFECT_BLINK,
EFFECT_MARQUEE,
EFFECT_COUNT
};
uint8_t currentEffect = EFFECT_FLOW;
unsigned long lastEffectChange = 0;
unsigned long lastUpdate = 0;
void setup() {
delay(3000); // Safety delay
FastLED.addLeds(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(115200);
}
// Full color water effect
void flowEffect() {
static uint8_t hue = 0;
static uint8_t pos = 0;
// Gradually turn off all LEDs
fadeToBlackBy(leds, NUM_LEDS, 10);
// Set a colored light spot at the current position
leds[pos] = CHSV(hue, 255, 255);
// Move location
pos = (pos + 1) % NUM_LEDS;
// Change the hue
hue += 3;
FastLED.show();
delay(30);
}
// Full color flashing effect
void blinkEffect() {
static bool lightsOn = false;
static uint8_t hue = 0;
if(lightsOn) {
// Random color of full light strip
fill_solid(leds, NUM_LEDS, CHSV(hue, 255, 255));
hue += 5;
} else {
// All off
fill_solid(leds, NUM_LEDS, CRGB::Black);
}
lightsOn = !lightsOn;
FastLED.show();
delay(lightsOn ? 200 : 800); // On for 200ms, Off for 800ms
}
// Marquee effect
void marqueeEffect() {
static uint8_t hue = 0;
static int position = 0;
static int tailLength = 15;
// Gradual fading
fadeToBlackBy(leds, NUM_LEDS, 20);
// Create a Marquee
leds[position] = CHSV(hue, 255, 255);
// Creating a gradient tail
for(int i = 1; i < tailLength; i++) {
int pos = (position - i + NUM_LEDS) % NUM_LEDS;
leds[pos] = CHSV((hue + 10*i) % 255, 255, 255 - (255/tailLength)*i);
}
position = (position + 1) % NUM_LEDS;
hue += 2;
FastLED.show();
delay(50);
}
void loop() {
// Switch effects every 30 seconds
if(millis() - lastEffectChange > 30000) {
currentEffect = (currentEffect + 1) % EFFECT_COUNT;
lastEffectChange = millis();
FastLED.clear();
FastLED.show();
}
// Execute the current effect
switch(currentEffect) {
case EFFECT_FLOW: flowEffect(); break;
case EFFECT_BLINK: blinkEffect(); break;
case EFFECT_MARQUEE: marqueeEffect(); break;
}
// Brightness control (optional)
// adjustBrightness();
}
// Optional: Switch effects via serial port commands
void serialEvent() {
while(Serial.available()) {
char c = Serial.read();
if(c >= '0' && c <= '2') {
currentEffect = c - '0';
FastLED.clear();
FastLED.show();
}
}
}
// Optional: Brightness adjustment function
void adjustBrightness() {
int potValue = analogRead(A0); // Connect the potentiometer to A0
int newBrightness = map(potValue, 0, 1023, 0, 255);
FastLED.setBrightness(newBrightness);
}
5. Demonstration Video
Here is a video showing how to control the light changing effect of a WS2812 LED strip with Arduino.
WS2812B LED strips can be customized with a variety of lighting effects with the help of Arduino UNO. By using a suitable power supply, stable wiring and a suitable code library, you can easily achieve smooth full-color animations.
Please contact us if you need any help controlling WS2812B programmable LED strips with Arduino UNO.