Skip to main content

ws2812

Control WS2812 (NeoPixel) addressable RGB LED strips with color patterns and animations.

Overview

The ws2812 node controls WS2812 (NeoPixel) addressable RGB LED strips, allowing individual pixel color control, fill patterns, rainbow animations, and brightness adjustment. Each LED in the strip can be independently set to any 24-bit color (or 32-bit with RGBW strips), enabling rich visual feedback, status indicators, ambient lighting, and dynamic light shows for IoT dashboards and smart environments.

16M
Colors (24-bit)
800kHz
Data Rate
5V
LED Voltage
60mA
Per LED (max)

Properties

Property Type Required Default Description
pin number Yes 18 Data GPIO pin (must be PWM-capable, BCM numbering)
ledCount number Yes 8 Number of LEDs in the strip
brightness number No 255 Global brightness level (0-255)
stripType select No "GRB" Color order: "RGB", "GRB", "RGBW", or "GRBW"
frequency number No 800000 Signal frequency in Hz (800kHz for WS2812B)

Inputs

msg.payload

Object with action and color parameters.

{
  "action": "fill",
  "color": "#FF0000"
}
"fill" Fill all LEDs with one color
"set" Set a specific LED (requires led index)
"rainbow" Apply rainbow gradient across strip
"clear" Turn off all LEDs

Outputs

Strip State

Outputs current strip state and action confirmation.

{
  "ledCount": 8,
  "brightness": 255,
  "action": "fill",
  "timestamp": 1709251200000
}

Input Format Details

Fill All LEDs

{
  "action": "fill",
  "color": "#00FF00"
}

Set Single LED

{
  "action": "set",
  "led": 3,
  "color": "#0000FF"
}

Set Multiple LEDs

{
  "action": "set",
  "colors": [
    "#FF0000", "#00FF00",
    "#0000FF", "#FFFF00",
    "#FF00FF", "#00FFFF",
    "#FFFFFF", "#000000"
  ]
}

Rainbow Pattern

{
  "action": "rainbow"
}

Wiring / Connection Diagram

WS2812 LED Strip to Raspberry Pi

  Raspberry Pi                    WS2812 LED Strip
  +-----------+                  +--[LED0]--[LED1]--[LED2]-- ... --[LEDn]--+
  |           |    330Ω          |                                         |
  |  GPIO 18  |---[Resistor]-----| DIN (Data In)                          |
  |           |                  |                                         |
  |  GND      |---[Ground]-------| GND                           GND      |
  |           |                  +------------------------------------------+
  +-----------+                        |                             |
                                       |                             |
   External 5V Supply                  |                             |
   +----------+                        |                             |
   | 5V  (+)  |------------------------+ VCC                        |
   | GND (-)  |------------------------+ GND                        |
   +----------+                                                DOUT (unused
                                                               or to next strip)
  Power Calculation:
  Each LED draws up to 60mA at full white
  8 LEDs = 480mA max, 60 LEDs = 3.6A max
  Always size your power supply accordingly!

Important: Use a 330 ohm resistor on the data line. Add a 1000uF capacitor across the power supply. For long strips (60+ LEDs), inject power at multiple points to prevent voltage drop.

Example Use Cases

Temperature Status Indicator

Map temperature readings to a color gradient on the LED strip (blue=cold, green=normal, red=hot).

dht22 function ws2812
[
  {
    "id": "temp-sensor",
    "type": "dht22",
    "pin": 4,
    "interval": 5000
  },
  {
    "id": "temp-to-color",
    "type": "function",
    "func": "var temp = msg.payload.temperature;
var color;
if (temp < 18) color = '#0000FF';
else if (temp < 25) color = '#00FF00';
else if (temp < 30) color = '#FFAA00';
else color = '#FF0000';
msg.payload = { action: 'fill', color: color };
return msg;"
  },
  {
    "id": "status-strip",
    "type": "ws2812",
    "pin": 18,
    "ledCount": 8,
    "brightness": 128,
    "stripType": "GRB"
  }
]

Dashboard Color Picker Control

Use a color picker widget on the dashboard to set LED strip color in real time.

color-picker change ws2812
[
  {
    "id": "picker",
    "type": "color-picker",
    "label": "LED Color"
  },
  {
    "id": "format-cmd",
    "type": "change",
    "rules": [
      {
        "t": "set",
        "p": "payload",
        "to": "{ "action": "fill", "color": payload }",
        "tot": "jsonata"
      }
    ]
  },
  {
    "id": "led-strip",
    "type": "ws2812",
    "pin": 18,
    "ledCount": 30,
    "brightness": 200,
    "stripType": "GRB"
  }
]

MQTT-Controlled Ambient Lighting

Control LED strip colors and patterns remotely via MQTT from any connected device.

mqtt-in ws2812
[
  {
    "id": "mqtt-leds",
    "type": "mqtt-in",
    "topic": "home/livingroom/leds",
    "datatype": "json"
  },
  {
    "id": "ambient-strip",
    "type": "ws2812",
    "pin": 18,
    "ledCount": 60,
    "brightness": 255,
    "stripType": "GRB",
    "frequency": 800000
  }
]

// MQTT payload examples:
// Fill:    { "action": "fill", "color": "#FF6600" }
// Rainbow: { "action": "rainbow" }
// Clear:   { "action": "clear" }
// Single:  { "action": "set", "led": 0, "color": "#FFFFFF" }

Common Use Cases

Ambient Lighting

Smart room and under-cabinet lighting control

Status Visualization

Visual bar graphs for sensor data and system health

Alert Indicators

Color-coded warnings for thresholds and alarms

Interactive Displays

Light shows, progress bars, and notification strips

Related Nodes