Skip to content

Contributed by Shenye, organized by Ai-Thinker

Ai-WB2: Web-Based Control of WS2812 LED Strips (Pending Testing) ​

WLED for BL602 ​

A WLED implementation based on the BL602 MCU, supporting web-based control of WS2812 LED strips.

Features ​

  • 🌈 RGB color control
  • 💡 Brightness adjustment (0-255)
  • 🎨 Multiple lighting effects:
    • Solid color mode
    • Rainbow effect
    • Color gradient
    • Breathing effect
    • Color wheel effect
  • 🌐 Web interface control
  • 📱 Responsive design, accessible from phones and computers
  • ⚡ Real-time status updates

Hardware Requirements ​

  • BL602 development board (e.g., Ai-Thinker WB2)
  • WS2812 LED strip
  • 1K-2K ohm pull-up resistor

Hardware Connection ​

BL602 GPIO11 ----[1K-2K resistor]---- VCC(3.3V) BL602 GPIO11 -------------------- WS2812 data input BL602 GND ----------------------- WS2812 GND External power ------------------ WS2812 VCC(5V)

** Note: WS2812 must use GPIO11, and an external pull-up resistor is required.

Software Configuration ​

1. WiFi Configuration ​

Edit the main/wifi_execute.c file to modify the WiFi connection information

Click to expand full code
c
#
define
 STA_SSID
"Your_WiFi_SSID"

// 替换为你的WiFi名称

#
define
 STA_PASSWORD
"Your_WiFi_Password"

// 替换为你的WiFi密码

2. LED Count Configuration ​

Edit the main/wled_server.c file to modify the LED count:

Click to expand full code
c
#
define
 LED_COUNT 46
// 修改为你的LED灯珠数量

Compiling and Flashing ​

  1. Enter the project directory:
Click to expand: cd
bash
cd
 applications/iot-solution/demo_wled
  1. Compile the project:
Click to expand: make
bash
make
  1. Flash it to the development board:
Click to expand: make flash
bash
make flash

Usage ​

  1. After power-on, the board automatically connects to the configured WiFi network
  2. Check the IP address obtained by the device via the serial port
  3. Access that IP address in a browser
  4. Use the web interface to control the LED strip

Web Interface Features ​

  • Power switch: turn the LED strip on/off
  • Brightness control: slider to adjust brightness (0-255)
  • Color selection: color picker to set the RGB color
  • Effect modes: select different lighting effects
  • Speed control: adjust the effect playback speed

API Endpoints ​

The project provides RESTful API endpoints for third-party control:

Get Status ​

Click to expand full code
html
GET /api/state

Control Endpoints ​

Click to expand full code
html
POST /api/power                    # 切换电源状态
POST /api/brightness?value=128     # 设置亮度 (0-255)
POST /api/color?r=255&g=0&b=0     # 设置RGB颜色
POST /api/effect?value=1          # 设置效果模式 (0-4)
POST /api/speed?value=128         # 设置效果速度 (1-255)

Effect Modes ​

  • 0 - Solid color mode: displays a single color
  • 1 - Rainbow effect: cycles through rainbow colors
  • 2 - Gradient effect: fades between two colors
  • 3 - Breathing effect: brightness breathes up and down
  • 4 - Color wheel effect: rotating color wheel

Troubleshooting ​

LED Not Lighting Up ​

  1. Check the GPIO11 connection and pull-up resistor
  2. Make sure the WS2812 is powered properly
  3. Check that the LED count is configured correctly

Cannot Connect to WiFi ​

  1. Check the WiFi SSID and password configuration
  2. Verify the WiFi signal strength
  3. Check the error messages on the serial output

Web Page Not Accessible ​

  1. Make sure the device is connected to WiFi and has an IP
  2. Check the firewall settings
  3. Try a different browser

Development Notes ​

The project is built on the following components:

  • FreeRTOS: real-time operating system
  • LwIP: TCP/IP protocol stack
  • WS2812 driver: implemented based on the IR module
  • HTTP server: a self-implemented lightweight server

License ​

This project is open source under the MIT license.

Contributing ​

Issues and Pull Requests are welcome to improve the project.

Attachment: demo_ws2812.zip

Attachment: demo_ws2812.zip

PS: Current progress — it compiles. No errors. Whether it runs and works, I don't know. ​

Released under the MIT License. Build Time 2026-09-30 17:31:25