Example 14: RGB NeoPixel (WS2812B)
About 2 min
Example 14: RGB NeoPixel (WS2812B)
Experiment Overview
Drive WS2812B (NeoPixel) RGB LEDs via single-wire protocol for full-color control. FastBee has a built-in NEO_PIXEL peripheral type (type: 45), supporting color, brightness and LED count settings.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| DATA | GPIO4 | WS2812B data pin (DIN) |
WS2812B power supply recommends 5V, data line can connect directly to 3.3V GPIO (most WS2812B are compatible).
JSON Configuration Example
{
"peripherals": [
{
"id": "ws2812b",
"name": "WS2812B RGB LED",
"type": 45,
"enabled": false,
"pins": [4],
"params": {
"count": 8,
"brightness": 64
}
}
]
}Parameter Description
| Parameter | Description | Range |
|---|---|---|
| count | Number of LEDs | 1~255 |
| brightness | Global brightness | 0~255 |
Peripheral Execution Linkage
Scenario 1: Set Single LED Color (Platform Trigger)
Function: Set LED #0 to red via cloud platform command
Web Interface Configuration Steps
Step 1: Create Rule
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Set RGB Color - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Platform Trigger Receive cloud platform commands Operator Select Match Pattern Match command Comparison Value {"cmd":"color"}Color control command
Step 3: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Set RGB
- Target Peripheral: Select
ws2812b - LED Index:
0(LED #0) - R Value:
255 - G Value:
0 - B Value:
0
Click Save button
Scenario 2: Set All to Same Color (Platform Trigger)
Function: Set all LEDs to green via cloud platform command
Web Interface Configuration Steps
- Create rule, name:
All Green - Trigger configuration:
- Trigger Type: Select Platform Trigger
- Operator: Select Match Pattern
- Comparison Value:
{"cmd":"all_green"}
- Action configuration:
- Action Type: Select Fill RGB
- Target Peripheral: Select
ws2812b - R Value:
0 - G Value:
255 - B Value:
0
- Click Save
Common RGB Color Values
| Color | R | G | B | Description |
|---|---|---|---|---|
| Red | 255 | 0 | 0 | Pure red |
| Green | 0 | 255 | 0 | Pure green |
| Blue | 0 | 0 | 255 | Pure blue |
| White | 255 | 255 | 255 | White |
| Yellow | 255 | 255 | 0 | Yellow |
| Purple | 255 | 0 | 255 | Purple |
| Cyan | 0 | 255 | 255 | Cyan |
Notes
- Power: Each WS2812B draws ~60mA at full brightness, multiple LEDs need independent 5V power
- Level: Some WS2812B need 5V logic level, add level shifting or 330Ω resistor in series on DIN
- Timing Sensitive: WS2812B has strict timing requirements, recommend using RMT peripheral (ESP32 uses it by default)
- Refresh Rate: More LEDs = slower refresh, 100 LEDs ~3ms
- Data Order: Color order may be GRB instead of RGB, depending on model
