How to Wire and Code WS2818 LED Strip on ESP8266

How to wire and code WS2818 LED strip on ESP8266?

If you want to use the ESP8266 controller to create a colorful lighting system, this article will help you: Master the wiring skills of WS2818 LED strips and ESP8266, and learn how to write ESP8266 control code to achieve professional-level lighting control effects. Just follow the steps below to make your LED strips shine!

1. Materials Required

Power Supply

Output

  • Voltage: DC5V
  • Current: Up to 40A
  • Power Rating: 200W

Input

  • Voltage Range: AC110V/220V (dual input supported, switch-selectable)
  • Sensitive to voltage drop:When supplying power over long distances, the voltage drop is very obvious (for example, there may be only 4V left at the end of a 5-meter wire), so the distance needs to be shortened or the voltage needs to be compensated.

  •  

Power Supply

Output

  • Voltage: DC12V
  • Current: Up to 33.3A
  • Power Rating: 400W

Input

  • Voltage Range: AC 110V/220V (dual input supported, switch-selectable)
  • Safety and efficiency: Safer than 24V/48V (lower risk of electric shock), more suitable for high-power devices than 5V.
Arduino 5V LED Power Supply
 5V LED Power Supply
Arduino 12V
12V LED Power Supply

For this setup:

  • DC5V Power to the the ESP8266 from the power supply (5 volts/GND wire) and DC12V to power the WS2818 Led strip.
  • Sufficient current for many Led strips
  • Industrial-grade reliability and good heat dissipation and ventilation

ESP8266 Control Board

ESP8266
ESP8266 Control Board Area Pin Introduction

Model: ESP8266
Operating Voltage: 3.3V-5V
Input Voltage (recommended): ESP8266 has two voltages, one is the external power supply port is 5V, Type-C5V, output pin 3.3V
Digital I/O Pins: 5
Maximum operating pixels: 800-1000 pixels
Compatible protocols: WS2812/WS2815 and other mainstream LED protocols
Application of ESP8266: With Wi-Fi function and strong cost performance, ESP8266 is widely used in the Internet of Things and smart home
Programming Interface: USB Type-C

Use in this setup:

  • The ESP8266 controller is used as a controller to send digital data signals to the WS2818 LED strip.
  • The LED strip is connected to a DC12V power supply and the controller is connected to a 5V 200w power supply.
  • It should be noted that the GPIO of the ESP8266 is a 3.3V logic level, so the GPIO pins need to be level-converted before connecting to the LED strip signal pins. The “D1” interface of the WS2815 LED strip is connected to the 5V data output pins (such as HU1-HU4) in the level converter through a wire, and then connected to the digital I3 interface through a 3.3V (LU1-LU4) interface. The positive pole of the strip is connected to the positive pole of the DC12V power supply, and the negative pole is connected to the negative pole of the DC12V power supply. “B1” does not need to be connected

WS2818 LED Strip

DA5 12V WS2818
60LEDs/m WS2818 LED Strip

Type: External IC, 1 IC controls 3 LEDs, with break continuous function
Voltage: DC12V
Communication protocol: Dual signal, 8-bit, 800-1200Hz
Features: DC12V power supply, 256-level brightness adjustment, dynamic streamer, rainbow gradient and other special effects
LED density: 60 LEDs/m

Accessories & Tools

  • Connecting Wires: Use appropriate gauge, e.g., 18–22 AWG,18-22AWG is the wire diameter that best meets international standards for use on led strips
  • Logic-Level Shifter: Must use 4-way level converter

2. Wiring Schematic

Please check below for a diagram of how to control the WS2818 led strip via the ESP8266 controller.

esp8266 ws2818 schematic
How to Control WS2818 LED Strip with ESP8266 Wiring Diagram

Note:
1.The control board current of ESP8266 is less than 500mA;
2. The current of the light strip is too large, please use an external power supply to power the light strip;
3. The DC3.3 interface is the voltage output port of the control board and cannot be connected to the power supply;
4. The led strip is powered by DC12V, and the power supply range of the control board is DC3.3-9V, so the control board is powered by DC5V alone;
5. It is worth noting that the wiring methods of RGB and RGBW are exactly the same, but the programs are completely different and cannot be mixed;
6. The more points, the lower the refresh rate;
7. Note that the GPIO of ESP8266 is 3.3V logic level, so the GPIO pin needs to be converted and then connected to the signal pin of the light strip.

3. Connection Diagram

esp8266 ws2818
How to Control WS2812B LED Strip with ESP8266 LEDSuntech

Tips:

  • Short, direct data wire from ESP8266 to DIN
  • Safety terminal connection on power supply
  • Always disconnect power before rewiring

4. Code Upload

Software: Arduino IDE

Library Used: FastLED

Below is the code written by LedSuntech’s professional engineering team:

				
					#include 

#define LED_PIN 19 // LED strip data pin

#define NUM_LEDS 80 // Number of LEDs

#define BRIGHTNESS 128 // Initial brightness (0-255)

#define LED_TYPE WS2812B

#define COLOR_ORDER GRB // Most WS2812s are GRB order

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 color light spot at the current position
leds[pos] = CHSV(hue, 255, 255);

// Move position
pos = (pos + 1) % NUM_LEDS;

// Change hue
hue += 3;

FastLED.show();
delay(30);
}

// Full color blinking effect
void blinkEffect() {
static bool lightsOn = false;
static uint8_t hue = 0;

if(lightsOn) {
// Random color for all lights
fill_solid(leds, NUM_LEDS, CHSV(hue, 255, 255));
hue += 5;
} else {
// All lights 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 extinguishing
fadeToBlackBy(leds, NUM_LEDS, 20);

// Create a marquee
leds[position] = CHSV(hue, 255, 255);

// Create a gradient tail
for(int i = 1; i  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 step-by-step visual guide to controlling dynamic lighting effects of a WS2818 Led Strip using the ESP8266 controller, watch the demonstration video below:

Has this powerful ESP8266 microcontroller inspired you? More and more lighting designers are starting to use ESP8266 controllers to replace large pixel controllers. Follow the precise wiring diagram we provide to complete the connection, and you will succeed after using the optimized control code library! LEDSuntech technical team provides you with: one-to-one project support!LedSuntech provides many kinds of LED strips, whether it is a Regular LED Strip, SPI LED Strip, or DMX LED Strip. If you have any questions about the light strip, feel free to contact us!

Feel Free To Contact Us

We will reply your email within 12 hours.

Ask For A Quote