NeoPixels WS2812B

I’m in the process of using some neopixel for under kitchen lights. I have gone with WS2812B so a lot of the example that use the fastLED system are not compatible. SO I decided to try and roll my own.

I’ve started with the Adafruit_NeoPixel example code and Jon Oxers Superhouse Sonoff code and have started to combine.

The section I don’t understand is how to call the colorwipe section of the code and the also does not work. Any guidance would be great. I need to get the structure correct before adding other animations.

 * Simple example MQTT client to run on the Itead Studio Sonoff with OTA
 * update support. Subscribes to a topic and watches for a message of
 * either "0" (turn off LED and relay) or "1" (turn on LED and relay)

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>

#define PIN 1
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_RGBW + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

/* WiFi Settings */
const char* ssid     = "cc";
const char* password = "cc";

/* Sonoff Outputs */
//const int relayPin = 12;  // Active high
//const int ledPin   = 13;  // Active low

/* MQTT Settings */
const char* mqttServer = "";
const int mqttPort = 1883;
const char* mqttUser = "cc";
const char* mqttPassword = "cc"; //cc
const char* mqttTopic = "/Kichen/UNLight";   // MQTT topic
IPAddress broker(192,168,1,135);          // Address of the MQTT broker
#define CLIENT_ID "KichenNodeMU"         // Client ID to send to the broker

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);;

 * MQTT callback to process messages
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print("] ");
  for (int i=0;i<length;i++) {

  // Examine only the first character of the message
  if(payload[0] == 49)              // Message "1" in ASCII (turn outputs ON)
   colorWipe(strip.Color(33, 255, 0, 255), 50);
   Serial.print("should be on Now  ");// White RGBW
    //digitalWrite(ledPin, LOW);      // LED is active-low, so this turns it on
    //digitalWrite(relayPin, HIGH)
  } else if(payload[0] == 48)       // Message "0" in ASCII (turn outputs OFF)
    (strip.Color(33, 22, 99, 0), 50);
     Serial.print("should be OFF Now  ");
    //digitalWrite(ledPin, HIGH);     // LED is active-low, so this turns it off
    //digitalWrite(relayPin, LOW)
  } else {
    Serial.println("Unknown value");

WiFiClient wificlient;
PubSubClient client(wificlient);

 * Attempt connection to MQTT broker and subscribe to command topic
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect(CLIENT_ID)) {
    } else {
      Serial.print("failed, rc=");
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying

 * Setup
void setup() {
  strip.begin();; // Initialize all pixels to 'off'
 //Serial Etc
  WiFi.begin(ssid, password);
  Serial.println("WiFi begun");
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");

  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]

  // No authentication by default
  // ArduinoOTA.setPassword((const char *)"123");
  ArduinoOTA.onStart([]() {
  ArduinoOTA.onEnd([]() {
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if      (error == OTA_AUTH_ERROR   ) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR  ) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR    ) Serial.println("End Failed");
  Serial.print("IP address: ");
  /* Set up the outputs. LED is active-low */
 // pinMode(ledPin, OUTPUT);
 // pinMode(relayPin, OUTPUT);
  //digitalWrite(ledPin, HIGH);
  //digitalWrite(relayPin, LOW);

  /* Prepare MQTT client */
  client.setServer(broker, 1883);

 * Main
void loop() {
  if (WiFi.status() != WL_CONNECTED)
    Serial.print("Connecting to ");
    WiFi.begin(ssid, password);

    if (WiFi.waitForConnectResult() != WL_CONNECTED)
    Serial.println("WiFi connected");

  if (WiFi.status() == WL_CONNECTED) {
    if (!client.connected()) {
  if (client.connected())

According to that code you need to send a payload of “1” on the mqtt topic “/Kichen/UNLight”

I suggest you change the topic to “Kitchen/UNLight”. Having a topic starting with “/” is not good MQTT practice.

What makes you say the ws2812b isn’t compatible with FastLed? I use them with my Nodemcu LED controller with no issues at all.

I will remove the first “/” tonight thanks.

I can send and the controller receives the MQTT message (i print it to the serial).

The issue is the if statement and the colour wipe not working.

I saw your code and videos and they are great! The neo’s i have are rgbw so my understanding and searching was that fast led was only good for rgb?

if ((char)(payload[0] == '1')
} else if ((char)(payload[0] == '0')

Ah, I didn’t realize you were using RGBW - definitely not yet supported by FastLED (though I think it’s on the list for a near term upgrade).


Back again, having thought that I needed a level changer I have installed a 74AHCT125 in the circuit so send 5V logic to the LEDs.

I’m still having problems with getting the LEDs to change. The MQTT part is working and I am receiving the topic and using the serial print function to print out a status:

Message arrived [/Kichen/UNLight] 1
should be on Now  Message arrived [/Kichen/UNLight] 0
should be OFF Now  Message arrived [/Kichen/UNLight] 1
should be on Now  Message arrived [/Kichen/UNLight] 0
should be OFF Now  Message arrived [/Kichen/UNLight] 1
should be on Now

So from this I am happy with the MQTT.

My issue appears to be the command to strip. I don’t even appear to be sending clear correctly:

void setup() {
  strip.begin();; // Initialize all pixels to 'off'

This should boot up with no LEDs on.

I have a feeling it’s the structure and layout of my code but unsure where I am going wrong. Anyone have any ideas?

I have a feeling it could be your wiring to the LEDs.
The library works, it’s proven.
The MQTT works, you’ve proven it.
The LEDs don’t. Hence probably hardware related.

Yep agreed the parts work separately.

I have run the neopix test code and it cycles the colours chases etc. So i can confirm the wiring is good.

I think it is the instruction when a message is received that must be an issue. I’ve found another thread so will take a look and report back.

Will also strip down the code to the bare bones.


@SabreFrenzy I was able to get my SK6812 RGBW strips working with the fork and @bartus library