Led blink using nodejs


I am newbie here. I am trying to get the LED light working with Nodejs. I am using Pi3 with GroviPI kit.

I have tried the python code for Led blinking and it works fine but I want to do the same thing using nodejs but can’t get it to work so far.

I am connecting my led to D4 . I have also tried with Analog 1 but same issue.

Not sure which method I should use in nodejs.
When I try the below code

var GrovePi = require(‘node-grovepi’).GrovePi;

var Commands = GrovePi.commands;
var Board = GrovePi.board;
var LightAnalogSensor = GrovePi.sensors.LightAnalog;

var board = new Board({
debug: true,
onError: function(err) {
console.log(‘Something wrong just happened’);
onInit: function(res) {
if (res) {
console.log('GrovePi Version :: ’ + board.version());
var lightSensor = new LightAnalogSensor(4);
console.log(‘Light Analog Sensor (start watch)’);
lightSensor.on(‘change’, function(res) {
console.log(‘Light onChange value=’ + res);


It shows the following

Any help?


@hazem_salem sorry for being so late with this! Somehow I didn’t see this. Apologies,

Your code uses the light sensor which is a device that reads the amount of light in its environment. You would need to use a digital sensor in order to control a digital output device like an led.

I hope this helps



I just added an example to blink an LED
It will soon be part of Raspbian for Robots and you’ll be able to pull it in via DI Update.