Skip to content
PekawayPekaway
RGB control with WLED

RGB control with WLED

WLED is an open source software developed by Aircookie and is very popular in the maker scene. With WLED it is possible to control LED strips in your own WLAN using an app. The software offers a comprehensive catalog of setting options and effects, and in principle each LED can be controlled individually. In addition, WLED offers the option of control via an http API, Art-Net, DMX control and other protocols. In this case we are interested in control via http request.

material

In our tutorial we use the

WLAN LED pixel controller from cod.m

paired with a

12V WS2815 LED strip from BTF-Lighting.

WLED is already installed on the Pixel Controller, if you want to start slowly and at a lower cost, you can use an ESP8266 and a 5V LED strip. Flashing the software is very easy and you can Project pages be taken.

WLED configuration

After we have connected our LED strip to the controller (VCC: red, GND: white, DATA: green) we can supply it with power (12V). As soon as the controller has booted up, it opens an access point ("WLED-AP"), which we log into and enter the data for our existing WLAN.

Now we look for the new IP of the controller in our network, either directly in the router or via an IP scanner. We simply enter this IP address into a browser and we will see the WLED web interface.

Under "Config" and then "LED Preferences" we specify what type of LED strip we are using and, above all, how many LEDs it has in total. We also have to adjust the GPIO pin through which the data is sent. In our case, this is pin 18. Since our strip is 5 m long and has 30 LEDs/m, we end up with a total of 150 LEDs.

We can now test the strip directly on the main page of the interface. If everything is wired and set up correctly, we can now set colors and effects.

Node-RED

We continue in Node-RED, since we don't just want to control our LEDs via app, but also want to implement automation.

There are already nodes for WLED, but as mentioned, we want to use control via http request, which looks a bit more complicated, but is actually not that difficult. To get information about the current state, simple GET requests to the following endpoints are sufficient:

An overview of the adjustable effects:

http://<wled-ip>/json/eff</wled-ip>

The palette, i.e. possibilities of ready-made color schemes:

http://<wled-ip>/json/pal</wled-ip>

Software version, IP address, MAC address, etc. etc.:

http://<wled-ip>/json/info</wled-ip>

Current state of the LEDs, on/off, color, intensity, etc.:

http://<wled-ip>/json/state</wled-ip>

So we see that we can override certain values ​​with a JSON object. For example, if we now create a payload with {"on":false"} via POST request to the API (/json/state), then our strip goes out.

You can find a few examples if you import the flow at the very bottom of the page.

The idea behind the nodes in the lower left area is that you control a strip based on the battery charge level. To do this, we have divided the strip into 5 segments and indicate the battery values ​​in increments of 20 up to 100%. If the battery is over 80%, the entire strip lights up green, with a slight fade effect everywhere. If it is under 80%, the strip changes color and one segment lights up less, until at under 20% only the first part of the strip lights up red. But that is just an example of what you could do.

In the payload we see "transition" at 1, which stands for 100ms and is the transition time between the colors. The segment is specified with variables to make the whole process less static. "fx" is the ID of the effect we are using, the ID can be found easily using the GET request described above. "sx" is the speed of the effect, we only want a slow fade at this point.

In the function node before "set payload" the variables are defined, including the color. We can specify up to 3 colors ourselves that the respective effect should use, but not every effect can display these 3 colors, some only use two or one color, or a "rainbow" animation will be colorful either way...

Remember that you have to adjust the IP address in the http nodes.

Links and tips

In WLED there is a setting option "Sync", which results in a broadcast. If there are several WLED controllers in the network, the colors and effects are synchronized.

You can create zones by simply sending POST requests to multiple IP addresses in Node-RED.

API WLED:

https://kno.wled.ge/interfaces/json-api/

Sample code for Node-RED:

https://share.12-s.de/s/nT3ZGwD9jmpFAGM

Left:

https://youtu.be/R5oNajxnkic

Here you can see what it will look like in the end. Have fun with it. :)

Leave a comment

Your email address will not be published..

more tutorials

Open Source needs support

become Patron now

More projects, more tutorials and more supported devices. Our community is growing and would appreciate your support. So become a patron now to always receive the latest content and support the VAN PI project at the same time.

Become a Patron
Cart 0

Your cart is currently empty.

Start Shopping