Node-RED with WS2812B Addressable RGB LED Strip

Addressable RGB LED strips are just awesome! You can control each individual pixel of the strip, allowing you to produce beautiful effects. However, controlling these kind of strips it’s not always easy. So, in this project we’re going to show you how to build a web application with Node-RED and Raspberry Pi to control an addressable RGB LED strip to make your life simple.

Watch the video demonstration

Prerequisites

If you like home automation and you want to learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino. I recommend that you download my course: Build a Home Automation System with Node-RED, ESP8266 and Arduino.

Project overview

Here’s some important aspects about the Node-RED application built in this project:

  • The addressable RGB LED strip will be controlled using the neopixel node that you need to install;
  • In the application, you can select individual LEDs and set its color using a color picker;
  • You can select the strip color either by using the color picker or a drop-down menu with preset colors;
  • The application also allows you to display a moving rainbow effect on the strip;
  • Finally, you’ll have a “Clear” button to unlit all the LEDs on the strip.

Parts required

In this project we’ll be controlling the WS2812B addressable RGB LED strip. For that you’ll need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Wiring the WS2812B RGB LED Strip

With your Pi shutdown, follow the next schematic diagram to wire the WS2812B RGB LED strip to your Pi. The WS2812B data pin should be controlled by the Pi’s GPIO18, because that’s the GPIO used by the neopixel node.

The pin used to control the strip may conflict with audio playback, so the pixels can go crazy and not work properly. If this happens, you need to add two lines to the config.txt file. In the Terminal enter the following:

pi@raspberrypi:~ $ sudo nano /boot/config.txt

In the file that opens, add the following two lines (anywhere should be fine):

hdmi_force_hotplug = 1
hdmi_force_edid_audio = 1

Press ctrl-X to save the file and then, when prompted, type Y and press enter. Reboot your Pi for the changes to take effect, and then proceed with the instructions.

Installing the neopixel Node-RED node

To control the WS2812B addressable RGB LED strip with Node-RED, you need to install node-red-pi-neopixel. First, you need to install the Neopixel python driver. So, in the Terminal window type the following (this may take a few minutes):

pi@raspberry:~ $ curl -sS get.pimoroni.com/unicornhat | bash

Then, install the node to control the LED strip:

pi@raspberry:~ $ node-red-stop
pi@raspberry:~ $ cd ~/.node-red
pi@raspberry:~/.node-red $ npm install node-red-node-pi-neopixel

Starting Node-RED

To start Node-RED, enter the following in the Terminal window:

pi@raspberry:~ $ node-red-start

To access Node-RED, open a tab in any browser on the local network and type the following:

http://Your_RPi_IP_address:1880

You should replace Your_RPi_IP_address with your Raspberry Pi IP address. If you don’t know your Raspberry Pi IP address, in the Terminal enter:

pi@raspberry:~ $ hostname -I

Creating the Node-RED Flow

Before creating the flow, make sure you have the rpi neopixels node, as show in the figure below. If you don’t have the node, check that you’ve followed the instructions above in the Installing the neopixel Node-RED node section.

Here’s the flow to control the WS2812B RGB LED strip.

As this flow is a bit complex, we recommend importing the flow we provide instead of building it from scratch. Then, you can make modifications to the flow, if necessary.

Importing the Node-RED flow

To import the Node-RED flow provided, go to the GitHub repository or click the figure below to see the raw file, and copy the code provided.

Next, in the Node-RED window, at the top right corner, select the menu, and go to Import Clipboard.

Then, paste the code provided and click Import.

Select the Number of LEDs

This flow was built for a strip with 14 LEDs. You’ll be probably using a different number of LEDs. So, you’ll need to make some changes to the flow.

WS2812B LED STRIP Node

Double click the WS2812B LED STRIP node, and change the number of LEDs in the first field.

Select LED Slider Node

You also should edit the Select LED Slider Node, so that you are able to select all the pixels on your strip with the slider.

Select LED Numeric Node

You need to edit the Select LED numeric node to match the number of LEDs on your strip.

Rainbow Effect Function Node

Edit the number of LEDs on the Rainbow Effect function node, as highlighted in the figure below. You need to do this, so that the rainbow effect spreads across the number of LEDs on your strip.

Adding More Preset Colors

This Node-RED application has a drop-down menu that allows to chose a color for the entire strip. We’ve added some preset colors, but you can add more colors if you like. For that, double-click on the Select Strip Color drop-down node and add more options. You should set the color in RGB.

Node-RED UI

After making all the necessary changes, click the Deploy button to save all the changes.

Now, you Node-RED application is ready. To access Node-RED UI and see how your application looks, access any browser in your local networks and type:

http://Your_RPi_IP_address:1880/ui

Your application should look as in the following figure.

Wrapping up

In this project we’ve made a Node-RED application to control the WS2812B RGB LED strip using the neopixel node. We hope you’ve liked this project, and have fun controlling your LED strip.

If you like this project, you may also like:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

37 thoughts on “Node-RED with WS2812B Addressable RGB LED Strip”

  1. Your article tells me to connect my pixels data line to GPIO 17, “because that’s the GPIO used by the neopixel node.” The neopixels are controlled by a fancy hijacking of a PWM pin and in every bit of Python code I’ve seen (or written myself), they are connected to GPIO 18, which is a PWM pin. The Python library code says pin 18. The Pimoroni “schematic” for the Unicorn hat says pin 18 too
    pinout.xyz/pinout/pin12_gpio18 So I have to conclude you’ve got a typo.
    Also: when using this on a Pi Zero, you really do need to disable audio. The Pimoroni install script enables it and maybe it works if you route audio to HDMI, but I’m not. You need to edit /boot/config.txt:
    # Enable audio (loads snd_bcm2835)
    # disabled for neopixel use on pwm gpio 18
    #dtparam=audio=on
    Without this it absolutely does not work (I know, I just changed it and now it does work).
    Thanks for the bootstrap!

    Reply
    • Hi Jeff.
      You are right! It was a typo. I’ve already fixed it.
      We also added how to edit the config.txt file.
      Thanks for noticing and letting us know. 🙂

      Reply
    • Hi Ethan.
      This project uses Node-RED to control the RGB LED strip.
      What do you mean with using msg.brightness to control the brightness? What are you using to control the LED strip?
      Regards,
      Sara

      Reply
      • Hi ! Sara.
        THX for replying my question. Im using the Node-Red to control the RGB LED just like the tutorial, but im not using the strip, instread im using the Neopixel 8×8 Matrix. The Node-Red-Neopixel’s detail says it can use msg.brightness to control the led brightness dynamically, but i just can’t make it work…………Can you help me with that?
        THX AGAIN!!!

        Reply
    • You need to remove the 5v wire that is powering the RGB LED strip. Then, you use an external power supply that is connected to that 5V pin and the GND to GND. (The GND pins from the 2 different power sources need to be connected).

      Reply
  2. Hi,

    Hope you can hep.

    I have followed all the instructions but the WS2812B node says not available and is greyed out instead of green and ok. Everything is in the flow space and on the UI as per the instructions.

    If i pull in another rpi gpio node and set the gpio pin it says ok and is green.

    Any idea what could be happening as im stuck!

    Thanks
    Mike

    Reply
      • Hi.
        I also don’t know why that’s happening and how to fix it.
        If you find any solution to that problem, please share with us.
        Regards,
        Sara 🙂

        Reply
        • I had the same issue, I added a sudo to the “curl -sS get.pimoroni.com/unicornhat | bash” and everything loaded and worked fine.

          For the newbies like me cut and paste this (remove the quotes””)
          “sudo curl -sS get.pimoroni.com/unicornhat | bash”
          then something will happen!

          Reply
    • Hi.
      We have other readers complaining about the same issue.
      I have no idea why that’s happening.
      I also tried searching online for a reason and I can’t find anything about that.
      If anyone knows why that is happening and how to fix it, please share!
      Regards,
      Sara 🙂

      Reply
  3. Glad its not just me as Ive tried multiple times and re-read through the instructions and steps! Its driving me crazy as Im new to Node red and coding in general.

    I can confirm that my GPIO Pin 18 works fine. And if i run the unicornhat examples such as cross.py through terminal it all works with the neopixel lights. Just cant get the rpi neopixel node to connect

    Reply
    • Hi Michael.
      I’m sorry that is happening to you and to other of our readers.
      Maybe it is something wrong with the node itself.
      We have to try it out ourselves and understand what is going on.
      Regards,
      Sara 🙂

      Reply
  4. Hi,

    Nice tutorial, thanks!

    But i was wondering why you connect both 5v and 3.3v cables on the PI, and then change the 3.3v to 5v with the low level converter.

    Why not directly connect 5V to the led strip?

    PS. i have never used a breadboard before

    Reply
    • Hi. You can power the strip with 5V directly on the +5V pin.
      In this example, we’re connecting 3.3V and 5V to the level shifter because we want to convert the 3.3V signal to 5V.
      Powering the strip by connecting the +5V to the breadboard, in this case, is the same as connecting directly to the Pi 5V pin.
      I hope this is clear.
      Regards,
      Sara

      Reply
  5. Possible solution Michael Duckett. I had the same issue but with the dashboard nodes. Nothing seemed to help it always looked the same where node-red didn’t recognize the nodes. I even created a new img for the raspberry pi and node red didn’t change so I opened up node red from an incognito window and it fixed it. Try emptying your browser cache and hopefully that will work.

    Reply
  6. Hello
    I am really struggling to get this going.
    I have done everything to the dot, and all that happens is the lights all go crazy.
    All different colours. none of the commands in the ui works.
    I am very much a beginner, but really thought everything will work when I follow the instructions.
    Please help.
    Thanks in advance

    Reply
    • Hi.
      Double-check your strip model. Is it an WS2812B addressable RGB LED strip?
      How many LEDs are you controlling?
      How are you powering the strip?

      Did you follow the next suggestion?

      The pin used to control the strip may conflict with audio playback, so the pixels can go crazy and not work properly. If this happens, you need to add two lines to the config.txt file. In the Terminal enter the following:

      pi@raspberrypi:~ $ sudo nano /boot/config.txt

      In the file that opens, add the following two lines (anywhere should be fine):

      hdmi_force_hotplug = 1
      hdmi_force_edid_audio = 1

      Press ctrl-X to save the file and then, when prompted, type Y and press enter. Reboot your Pi for the changes to take effect, and then proceed with the instructions.

      Regards,
      Sara

      Reply
      • Hello Sara
        Thank you for your reply. It is in a WS2812B LED, 120 LED (60/m).
        I wired it exactly as the diagram in the tutorial. I power it through the RPI as shown.
        I installed everything as shown, and disabled the audio.
        What could be the possible problem?

        Reply
        • Hi.
          In our example, we’re only controlling 14 LEDs. It works fine controlling this small number of LEDs powered with the 5V coming from the Pi.
          However, with 120 LEDs, you need to power the strip with an external power source because the RPi probably can’t provide enough current.
          Additionally, you need to edit the number of LEDs in the Node-RED nodes.
          Did you do that?
          Regards,
          Sara

          Reply
          • Hello Sara
            I added the lines of code like you mentioned, and tried again.
            Each light is still a different colour.
            Even when selecting just a single colour, it does not work.
            I will add an external power source tomorrow and try again.
            I also changed the number of LEDs where mentioned.
            Will the current effect the colours of the LED lights though?
            Thank you for the help
            Lene’

          • Hi.
            An improper power supply leads to a weird behavior of the strip.
            So, yes. That can be the cause.
            Regards.
            Sara

          • hello Sara
            I reduced the number of LEDs to 10 and there is still no hope.
            I ran a program ./gpiotest and all gpios are good.
            Just to confirm as well I have a rpi3B.
            I have even tried running the lights through python3 and nothing.
            I am hopeless at the moment, I have also bought and tried another board and the same result.
            Thanks in advance

          • Hi again.
            I’m really sorry.
            At this moment, I’m out of ideas of what might be causing the issue 🙁
            Meanwhile, if you find out something, please share.
            Regards,
            Sara

  7. After using example flow from your website. WS2812B LED STRIP node will show “node-red:rpi-gpio.status.not-available”
    Is it happen on others? Should I try to re-check gpio readall?

    Reply
  8. The same thing happened to me.
    Go to the this page and look at the pre-requisites, install the drivers:
    https://flows.nodered.org/node/node-red-node-pi-neopixel
    After that edit the file config.txt using:
    sudo nano boot/config.txt
    comment the line:
    #dtparam=audio=on
    It’s working for me. Be careful with the power supply, if the voltage drops when turning on the LEDs you will have other problems.

    Reply

Leave a Reply to poodle pappa Cancel reply

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.