
Raspi Flowing Leds in NodeJs
Creating flowing LEDs (also known as a "running light" or "LED chaser") with Raspberry Pi and Node.js is a classic and fun electronics project! π‘π‘π‘ Letβs set it up step by step using the onoff
library.
π§° What You Need
Raspberry Pi (any model with GPIO)
4β8 LEDs
Resistors (330Ξ© for each LED)
Breadboard + jumper wires
π GPIO Pin Setup Example
LED Number | GPIO Pin | Pi Header Pin |
---|---|---|
LED1 | 17 | 11 |
LED2 | 18 | 12 |
LED3 | 27 | 13 |
LED4 | 22 | 15 |
You can extend this with more LEDs too.
π¦ Step 1: Install onoff
npm init -ynpm install onoff
π‘ Step 2: Create flowing-leds.js
const leds = [ new Gpio(17, 'out'), // LED1 new Gpio(18, 'out'), // LED2 new Gpio(27, 'out'), // LED3 new Gpio(22, 'out') // LED4];let index = 0;const delay = 200; // milliseconds between stepsconst interval = setInterval(() => { leds.forEach((led, i) => led.led => { led.writeSync(0); led.unexport(); }); console.log('\nFlowing LEDs stopped.'); process.exit();});
π Step 3: Run It
sudo node flowing-leds.js
Use
sudo
because GPIO access requires root privileges.
π§ Bonus Ideas
Reverse the flow: run backward after reaching the end
Flow back and forth like Knight Rider
Add a button to control speed or direction
Use PWM for fade-in/out effect (with
pigpio
)