Programming WS2818 Addressable LED Strips with Arduino

Table of Contents

Want to try programming WS2818 addressable LED strips with Arduino? This post walks you through setting things up, uploading your code with the Arduino IDE, and creating colorful effects with your lights.

1.Materials

12V LED Driver

  • Output Voltage: DC12V
  • Maximum Current: 33A
  • Power Rating: 400W
  • Input Voltage Range: AC200V-AC240V/ AC100V-AC120V
Arduino 12V

5V LED Driver

  • Output Voltage: DC5V
  • Maximum Current: 40A
  • Power Rating: 400W
  • Input Voltage Range: AC200V-AC240V
Arduino 5V LED Power Supply
5V Power Supply

Function:

  • The Arduino UNO is powered through its Vin and GND pins using a 5V supply.
  • A separate 12V power supply is used for the WS2818 LED strip, making it easy to extend the strip length when needed.
  • These power supplies offers efficient performance, durability, and stable operation.

 

WS2818 LED Strip

DA5 12V WS2818
12V 60LEDs/m WS2818 LED Strip

Parameters of this LED strip:

Voltage: DC12V
LED Qty.: 60LEDs/m
Pixels Qty.: 20Pixels/m
Color: RGB
Features: WS2818 LED strip is similar to WS2811 LED strip, but WS2818 LED strip is a Breakpoint Resume LED Strip. If one LED is damaged, the remaining LEDs can still work normally.

IC type: WS2818

Arduino Board

Arduino Control Board Area Pin Introduction
Arduino Control Board Area Pin Introduction

The Arduino Uno R3 is a strong choice for controlling addressable LED strips. It offers many digital pins, so you can connect different kinds of LED strips with ease. The PWM pin can adjust brightness and create smooth color transitions. Coding is simple with the Arduino IDE. Popular libraries like FastLED and Adafruit NeoPixel save time and effort. These tools make it easy to design lighting effects. The Uno R3 is also affordable, which is great for beginners and hobbyists. This board is popular for learning electronics and building prototypes. Many beginners use it for projects such as reading sensor data or controlling lights and motors. It is easy to use and there are plenty of community resources and expansion parts available. In this setup, the Arduino board acts as a controller.

Others:

  • Cables used to link the LED driver, WS2818 strip, and Arduino board.
  • A 3.3V level shifter is recommended for voltage protection of the Arduino (optional).

2.Wiring Diagram

Below is a wiring diagram showing how to connect the Arduino board, WS2818 LED strip, and an LED power supply from LEDSuntech.

Arduino WS2818 wire diagram
How to Control WS2818 LED Strip with Arduino Wiring Diagram

Note:

  • The Arduino board’s current draw should stay under 500mA.
  • Don’t connect the DC3.3/5V output port from the control board directly to a power supply if you are not using a level shifter.
  • For RGB types, keep under 500 pixels. For RGBW, stay below 375 pixels; for RGBWW, under 300. Higher pixel counts will reduce the refresh rate.

3. Connection Diagram

We’ve included some wiring photos below for your reference. While setting up, keep these tips in mind:

  • Use short, direct data wires from the Arduino to the DIN pin.
  • Make sure power supply terminals are securely connected.
  • Always turn off the power before adjusting any wiring.
Programming WS2818 Addressable LED Strips with Arduino
How to Control WS2818 LED Strip with Arduino LEDSuntech

4. Code Upload

Below are some sample codes for lighting effects, shared by LEDSuntech for your reference.

				
					#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 WS2812 LEDs use GRB order

CRGB leds[NUM_LEDS];

// Effect mode enumeration
enum Effects {
  EFFECT_FLOW,     // Rainbow flow effect
  EFFECT_BLINK,    // Rainbow blink effect
  EFFECT_MARQUEE,  // Marquee effect
  EFFECT_COUNT
};

uint8_t currentEffect = EFFECT_FLOW;
unsigned long lastEffectChange = 0;
unsigned long lastUpdate = 0;

void setup() {
  delay(3000); // Startup safety delay
  FastLED.addLeds(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  Serial.begin(115200);
}

// Rainbow flow effect
void flowEffect() {
  static uint8_t hue = 0;
  static uint8_t pos = 0;

  // Gradually fade out all LEDs
  fadeToBlackBy(leds, NUM_LEDS, 10);

  // Set a colored point at the current position
  leds[pos] = CHSV(hue, 255, 255);

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

  // Change hue
  hue += 3;

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

// Rainbow blink effect
void blinkEffect() {
  static bool lightsOn = false;
  static uint8_t hue = 0;

  if(lightsOn) {
    // Fill the entire strip with a random color
    fill_solid(leds, NUM_LEDS, CHSV(hue, 255, 255));
    hue += 5;
  } else {
    // Turn all LEDs 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;

  // Gradually fade out LEDs
  fadeToBlackBy(leds, NUM_LEDS, 20);

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

  // Create gradient tail
  for(int i = 1; i  30000) {
    currentEffect = (currentEffect + 1) % EFFECT_COUNT;
    lastEffectChange = millis();
    FastLED.clear();
    FastLED.show();
  }

  // Run the current effect
  switch(currentEffect) {
    case EFFECT_FLOW:    flowEffect();    break;
    case EFFECT_BLINK:   blinkEffect();   break;
    case EFFECT_MARQUEE: marqueeEffect(); break;
  }

  // Optional: Brightness control
  // adjustBrightness();
}

// Optional: Switch effects via serial 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 potentiometer to A0
  int newBrightness = map(potValue, 0, 1023, 0, 255);
  FastLED.setBrightness(newBrightness);
}
				
			

5. Demonstration Video of Lighting Effects

This WS2818 LED strip allows you to create a variety of lighting effects. You can use it with Arduino for your lighting projects.

If you need help controlling the WS2818 LED strip with Arduino, feel free to reach out to us.

Feel Free To Contact Us

We will reply your email within 12 hours.

Ask For A Quote