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
- You should be familiar with the Raspberry Pi – read Getting Started with Raspberry Pi.
- You should have the Raspbian operating system installed in your Raspberry Pi – read Installing Raspbian Lite, Enabling and Connecting with SSH.
- You need Node-RED installed on your Pi and Node-RED Dashboard.
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.
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.
In this project we’ll be controlling the WS2812B addressable RGB LED strip. For that you’ll need the following parts:
- Raspberry Pi Board – read Best Raspberry Pi Starter Kits
- WS2812B Addressable RGB LED strip
- Logic level converter module bss138
- Jumper wires
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:
[email protected]:~ $ 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):
[email protected]:~ $ curl -sS get.pimoroni.com/unicornhat | bash
Then, install the node to control the LED strip:
[email protected]:~ $ node-red-stop [email protected]:~ $ cd ~/.node-red [email protected]:~/.node-red $ npm install node-red-node-pi-neopixel
To start Node-RED, enter the following in the Terminal window:
[email protected]:~ $ node-red-start
To access Node-RED, open a tab in any browser on the local network and type the following:
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:
[email protected]:~ $ 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.
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:
Your application should look as in the following figure.
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:
- Node-RED with Raspberry Pi Camera (Take Photos)
- What’s the Best LED Strip For Your Project?
- Getting Started with Home Assistant on Raspberry Pi
- Build a Home Automation System with Node-RED
Thanks for reading.