ELEVATE YOUR BUSINESS WITH

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

Raspi Flowing Leds in NodeJs

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

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 NumberGPIO PinPi Header Pin
LED11711
LED21812
LED32713
LED42215

You can extend this with more LEDs too.


πŸ“¦ Step 1: Install onoff

bash

npm init -ynpm install onoff


πŸ’‘ Step 2: Create flowing-leds.js

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

bash

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)

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