Node.js Raspberry Pi GPIO Blinking LED

Here is a simple, complete, and beginner-friendly guide for Node.js Raspberry Pi GPIO Blinking LED.


๐Ÿ”ด Node.js Raspberry Pi โ€“ Blinking LED (GPIO Output)

Blinking an LED is the first step in learning GPIO programming on Raspberry Pi.
With Node.js, it becomes very easy and fun!


โœ… 1. What You Need

Hardware:

  • 1 ร— Raspberry Pi (any model with GPIO)

  • 1 ร— LED (any color)

  • 1 ร— 330ฮฉ resistor

  • Jumper wires

  • Breadboard (optional)


๐Ÿ“Œ 2. Wiring the LED

Connect as follows:

  • GPIO17 (Pin 11) โ†’ Resistor โ†’ LED Anode (+)

  • LED Cathode (โ€“) โ†’ Ground (Pin 6)

GPIO17 ----[330ฮฉ]----|>|---- GND

The long leg of the LED = positive (anode)


๐Ÿ“ฆ 3. Install GPIO Library

Use the onoff package:

npm install onoff

๐Ÿ’ก 4. Create the Blink Script

Create a file:

nano blink.js

Paste this code:


 


โ–ถ 5. Run the Script

Because GPIO needs root access:

sudo node blink.js

You should see the LED blink every 500ms.


๐Ÿงช Optional: Change Blink Speed

Fast blink (100ms):



 


โš  Important Safety Notes

  • Raspberry Pi GPIO pins output 3.3V only, never 5V.

  • Always use a resistor to prevent LED burn-out and GPIO damage.

  • Always stop your script before unplugging wires.

You may also like...