Audio Reactivity with: ESP32 + WLED + LedFx
Nov 4, 2024 • arduino
This will be an all in one post. I will show you how I flashed WLED onto an ESP32, wired up the LED strip, and synchronized my PC audio with the LEDs using LedFx.
You don't have to follow everything step by step, just skip to the part that's interesting to you. E.g., if you already have WLED set up, and want to know how to sync the audio, you can skip to the last step.
Step 0: Required parts
- 1x ESP32
- 1x 3V to 5V logic level shifter
- 1x Breadboard
- a bunch of jumper wires
- 1x LED strip (recommended: WS2812B for RGB or SK6812 for RGBW)
- 1x powerful enough PSU
Step 1: Flash WLED onto the ESP
WLED MoonModules to be precise. It contains more audio features than the standard version.
Step 1.1: Download the WLED binary
On the GitHub release page of the WLED project, you can find precompiled binary files. Scroll down until you see the "What's the right firmware for my device?" section.
For this project I used a normal ESP32, so I downloaded the ESP32, 4MB Flash, standard version.
Step 1.2: Flashing
On NixOS it's as simple as running this command in the folder where the downloaded binary file is located in:
nix-shell -p espflash
For the following step, you should have the ESP connected to your computer. Then flash the binary file with:
Your output should be similar to mine:
[2024-10-31T18:51:37Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-10-31T18:51:37Z INFO ] Connecting...
[2024-10-31T18:51:37Z INFO ] Using flash stub
[2024-10-31T18:51:39Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type: esp32 (revision v1.0)
Crystal frequency: 40 MHz
Flash size: 4MB
Features: WiFi, BT, Dual Core, Coding Scheme None
MAC address: 30:ae:a4:21:13:8c
[00:00:17] [========================================] 974/974 0x10000
[2024-10-31T18:51:57Z INFO ] Binary successfully written to flash!
Step 2: Wiring
When you look through other wiring diagrams, they often include a resistor between the data line and a capacitor near the LED strip's power line. I've never used either of them, and haven't had any issues running the strip for over 5 years. Sure, you can add them, but I won't be covering it here.
The red wire is 5V, yellow is 3V3, green is data, black (or white) is ground.
Step 3: Setup WLED
After everything's wired up, power on the circuit.
Step 3.1: Connect to WiFi
- Grab your phone and go to the WiFi settings. You should see a new network appeared under the name
WLED-AP
. Connect to it, the password iswled1234
. Or scan the following code to connect to it automatically:
- Now a new site should pop up, or if it didn't, go to http://4.3.2.1/. Click on
WIFI SETTINGS
. - Then
Scan
for existing networks. Select your network and enter your WiFi's password. If you want, you can set a static IP for your ESP there too. Otherwise, you'll need to check what IP the DHCP server assigned to it in the router settings. Scroll down and save. It should kick you out of the network afterwards.
Step 3.2: Choose the right LED settings
If everything is done right, you should be able to connect to the WLED's web dashboard by entering the IP in the browser. In the top navigation bar, click on Config
, then on LED settings
.
- Keep the brightness limiter enabled, if your power supply can't handle the maximum brightness of all LEDs. I use a 5V 10A power supply, that's why I have it disabled.
- Two very popular LED options are the
WS218B
andSK6812
. If you don't know which one you have, keep it onWS218x
, you can change it afterwards. - Later, when you change colors in the dashboard, and they don't match the expected color, that's when you probably should change the order. For now, keep it on
GRB
. - Enter the number of LEDs on the strip connected to the ESP. If you enter fewer than you actually have, the remaining LEDs won't be controllable.
- Enter
5
if you followed my wiring diagram.
When you're done, Save
it.
Go back to the dashboard and change the color to see if everything works. If it doesn't, click on the Power
button in the navbar, or take a look at the official troubleshooting page.
Step 4: Setup LedFx
To actually synchronize the PC audio output with the LEDs, I used LedFx. It even allows you to control the lighting of your RGB peripherals like mouse and keyboard in combination with OpenRGB.
Step 4.1: Install the app
Windows
You can download the app here, unpack it anywhere you want, and run the .exe
file.
Linux
For Linux, either follow this installation guide, or if you're in luck, check if your package manager provides a LedFx package.
NixOS
Add the ledfx
package to your nix configuration.
To auto start it on boot, you can add this code:
systemd.user.services.ledfx = {
enable = true;
description = "Start LedFX in the background at boot";
wantedBy = [ "graphical-session.target" ];
serviceConfig = {
ExecStart = "${pkgs.ledfx}/bin/ledfx";
Restart = "on-failure";
RestartSec = "5s";
};
};
Step 4.2: Go to the dashboard
Go to the LedFx's dashboard. It's usually on http://localhost:8888/. You'll be greeted by the tour assistant. If you want, you can skip it.
Step 4.3: Add the WLED device
The auto discovery feature didn't work for me. You can skip this step, if you already see your WLED on dashboard. Otherwise:
- Click on the blue
+
button. - Click on
Add Device
. - Select
wled
in the list. - Give your WLED device a name.
- Enter the IP address, that you previously used to access the WLED dashboard. Mine would be
192.168.3.21
. - Click on
Add
.
Step 4.4: Select an audio output
- Go to
Settings
. - Expand the
Audio
section. - Select your output device under
Audio device
.
Step 4.5: Select an effect
- Go to
Devices
. - Select your WLED device.
- Set
Effect Type
to anything from theClassic
category, likeBlade Power+
. It works the best for me.
Step 4.6: Try it out
If everything's set up right, the effect should sync with your music. Have fun!
Troubleshooting
I don't see the WLED access point after booting it for the first time
Make sure you didn't overwrite the bootloader while you were flashing the ESP. Check the output with esptool monitor
. If it boot loops without showing you anything WLED related, then download the bootloader for your ESP variant from here and flash it with this command:
espflash write-bin --baud 921600 0x0 esp32_bootloader_v4.bin
After a restart, LedFx falls back to my microphone
If you connect your headphones after LedFx is already running, it won't automatically switch the output. You'd have to reselect the output in the Web UI settings. (Please let me know if there's a way to fix it)