ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Raspi Rgb Led Websocket in NodeJs

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='22' AND `tutorial_submenu`='1416' AND `tutorial_status`=1 LIMIT 1

Raspi Rgb Led Websocket in NodeJs

Controlling an RGB LED on Raspberry Pi using WebSocket and Node.js is an awesome way to make interactive, real-time IoT apps! 🌈✨
With this, you can change LED colors from a web browser in real time.


🎯 What We'll Build

A web app where you pick a color (like red/green/blue/purple), and it updates the RGB LED on your Raspberry Pi using WebSocket communication.


🧰 What You Need

ComponentDescription
1 x RGB LEDCommon cathode preferred
3 x 330Ω resistorsFor each LED channel
Raspberry PiWith Node.js installed
Breadboard + wiresFor wiring


🎛️ Wiring (Common Cathode RGB LED)

LED PinConnect To
RedGPIO17 (Pin 11)
GreenGPIO27 (Pin 13)
BlueGPIO22 (Pin 15)
GNDGround (Pin 6)

Make sure you use resistors in series with Red, Green, and Blue.


📦 Setup Project

bash

const red = new Gpio(17, 'out');const green = new Gpio(27, 'out');const blue = new Gpio(22, 'out');// Serve static filesapp.use(express.static('public'));// WebSocket connectionio.on('connection', (socket) => { led => { led.<!DOCTYPE html>const socket = io(); function sendColor(r, g, b) { socket.emit('color', { r, g, b }); } </script></body></html>


🚀 Run the App

bash

sudo node server.js

Open your browser at:
👉 http://<your-raspberry-pi-ip>:3000

Click buttons and watch your RGB LED glow in real time! 🔴🟢🔵


🌟 Want to Go Next Level?

  • Use color picker input instead of buttons 🎨

  • Add brightness control (PWM with pigpio)

  • Control from mobile or over internet (port forwarding / ngrok)

  • Log actions or build automation rules

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql