Hardware & IoTLesson 100Free preview
RasPi Blinking LED
This lesson is part of Node.js · All levels
Summary
This lesson guides the most classic project on Raspberry Pi: turning on and off the flashing LEDs from the Node.js. You're going to frame the LED with the resistor to the GPIO pin, and then write the code that changes the pin value periodically. While simple, this project teaches the entire hardware-software work cycle.
Key points
- A LED band with resistors (e.g. 220-330 ohms) from GPIO pins to GND to protect the components.
- The blink code uses the setInterval which writes the opposite value for each period.
- Use writeSync for simple writing, or async write() with promise.
- Always handle SIGINT/SIGTERM to turn off the LED and remove the pin when you leave.
- The period of 500-1000 ms makes the blinking visible to the naked eye.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.