Introduction
Arduino is one single board on which you can do programing and control various devices, you can give output to any device using Arduino and also take some input from the device (sensor).
Node.js is a powerful JavaScript-based framework/platform built on Google Chrome's JavaScript Engine. Here we will use it with Arduino for IOT based projects.
For getting started with Node JS and Arduino follow the below steps.
- Download Node JS from here. And Install it.
- Download Git from here. And install it.
- Download Arduino IDE from here. And install it.
- Now we have requirement of following component,
- Arduino Uno Board with USB cable
- Bread Board
- Jumper cable
- LED
- Now we check if Node js is installed successfully or not.
So we make one folder in “D:\” drive, give it the name “Arduino” and right click in this folder and go to “Git Bash here” as shown in below image.
- It will open one window as shown in below image,
- Now type “node” in open windows as shown in below image,
- Now type the below command and hit the enter key.
console.log("Hello World!");
- Here you can show the above image. It will give output as “Hello World!” Now you can say that your Node Js is installed successfully.
- Now for Arduino communication with other devices, we use Node JS's “johnny-five” library. So first download it in node JS. So type “npm install johnny-five” command in GIT windows.
- On the successful installation of “johnny-five” it displays the output as shown in the below image.
- Now we use the Pin 13 of Arduino for our LED blink program. So connect Minus (-) terminal of Led to the ground of Arduino and plus (+) terminal of LED to Pin 13 of Arduino. As shown in the below image.
- Now connect the Arduino board to the computer using a USB cable so it gives power to it.
- Now open the Arduino IDE. as shown in the below image,
- Now go to the File>>Examples>>FIRData>>StandardFirData. It will open a new window.
- Now upload this program to Arduino by clicking on the “upload button” as shown in the figure. If it uploads successfully without any error then go to the next step.
- Now make a new JS file give the name “LEDBlink.js”, save it to “D:\Arduino” and write the following code to it. And save it.
- var Jfive = require('johnny-five');
- var nboard = new five.Board();
- nboard.on('ready', function() {
- var led = new jfive.Led(13);
- led.blink(1000);
- });
Herethe above code says that it will connect pin 13 of Arduino to Led and blink it every 1 second gap.
- Now we run this “LEDBlink.js” file from our GIT window. So run “node LEDBlink.js” as shown in the below image.
- Now it will start a Blinking LED every 1 second as shown in the below image.
Thanks for reading my article if you have any queries regarding this you can ask it in the comment section.