Node.js Raspberry Pi RGB LED with WebSocket
Below is a complete and easy Node.js + Raspberry Pi WebSocket RGB LED Controller guide.
You will build a real-time RGB LED controller using WebSockets, allowing you to adjust Red, Green, and Blue intensities instantly from a webpage.
🎨 Node.js Raspberry Pi RGB LED Control with WebSocket
This project will let you:
✔ Control RGB LED colors in real-time
✔ Use PWM to adjust brightness
✔ Communicate instantly via WebSocket
✔ Build a simple UI with sliders
🔧 1. Hardware Requirements
RGB LED Pins (Common Cathode recommended):
-
Red → GPIO17
-
Green → GPIO27
-
Blue → GPIO22
-
GND → Resistor → LED Ground
Circuit:
🧩 2. Install Required Packages
We use:
-
express → serve webpage
-
ws → WebSocket
-
pigpio → PWM for RGB LEDs
📄 3. Create Server Script
Create file:
Paste this code:
Save & exit: CTRL + X → Y → Enter
🎛️ 4. Create Web UI
Create HTML file
Paste:
Save & exit.
🚀 5. Start the WebSocket RGB Server
Output:
🌐 6. Open the Web Controller
On any device in same network:
👉 http://<raspberry-pi-ip>:3000
Example:
Move sliders → LED color updates instantly (no page refresh!).
