Figure 1: LED Blinking Program using NodeJs
You can read my previous articles here:
For Flashing/Blinking the LED on breadboard using Node.js follow below steps
Required list of components:
- 1 - Raspberry Pi device with 5 V power supply.
- 1 - Bread Board
- 1 - Male to Female jumper cable
- 1 - LED
Step 1: Firstly, connect the GPIO pin to the bread board as shown in figure.
Figure 2: Connect the GPIO pin to the bread board
Step 2: Here we use the PIN Number: “ 4 “ (As per number 4(pin rank 7) , third from the top – left ). For getting the output from the raspberry pi connect eh jumper wire from Raspberry PI GPIO pin “4” to bread board as shown in image,
Figure 3: Connect eh jumper wire from Raspberry PI GPIO pin
Step 3: Now take LED and put it on bread board as shown in image.
Connect the Plus terminal of LED to the Jumper cable (green cable in image) coming from the GPIO Pin “4” as shown in image,
Figure 4: Connect the Plus terminal of LED to the Jumper cable
Step 4: Now take another jumper cable (black cable in image) connect it the GPIO pin “Ground” as per number 3(Pin rank 6), third from the top right . And add other terminal of this wire to minus terminal of the LED as shown in figure.
Figure 5: Black cable in image
Step 5: Here for detecting the plus/minus terminal of LED, bigger (toll) terminal of LED is Plus and small (short) terminal of LED is minus. Or you can define it by cutting side part of LED that is Minus terminal.
Figure 6: Detecting the plus-minus terminal of LED
Step 6: Now write the Node.js program for blink LED every 1 second for 1 minute.
Here we use “Onoff ” module for the accessing the GPIO Pin of raspberry pi device.
- -- -- -- -- -- -- -- -- --
- var Gpio = require('onoff').Gpio,
- led = new Gpio(4, 'out');
- var iv = setInterval(function ()
- {
- led.writeSync(led.readSync() === 0 ? 1 : 0)
- }, 1000);
-
- setTimeout(function ()
- {
- clearInterval(iv);
- led.writeSync(0);
- led.unexport();
- }, 60000);
Step 7: Now run the program and the following output can be seen:
Figure 7: Program Show the Output
Now enjoy with your Raspberry Pi. If you liked my tutorial, then please comment on this.