Friday, April 19, 2024
ArduinoHow ToIoT HardwaresTutorials/DIY

Using Node js and Arduino with LED Blinking Program

Today In this Tutorial we talk about “Using Node js and Arduino with LED Blinking Program”.

Node.js is a very powerful JavaScript-based framework built on Google Chrome’s JavaScript V8 Engine. It is used to develop I/O intensive web applications like video streaming sites, single-page applications, and other web applications. Node.js is open source, completely free, and used by thousands of developers around the world.

Node isn’t a program that you simply launch like Word or Photoshop: you won’t find it pinned to the taskbar or in your list of Apps. To use Node you must type command-line instructions, so you need to be comfortable with (or at least know how to start) a command-line tool like the Windows Command Prompt, PowerShell, Cygwin, or the Git shell (which is installed along with Github for Windows).

Consequently, Node.js represents a “JavaScript everywhere” paradigm,unifying web application development around a single programming language, rather than different languages for server side and client side scripts.

Requirements

  • 1 x Arduino Uno board
  • 1 x LED

Software Requirement

  • Johnny-Five  :- Johnny-Five is an Open Source, Firmata Protocol based, IoT and Robotics programming framework, Released by Bocoup in 2012, Johnny-Five is maintained by a community of passionate software developers and hardware engineers. Johnny-Five programs can be written for Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, pcDuino3, Raspberry Pi, Particle/Spark Core & Photon, Tessel 2, TI Launchpad and more! More than 75 developers have made contributions towards building a robust, extensible and compatible ecosystem. We will achieve this with the Johnny-Five library for Node.js to program our robot. Johnny-Five uses a protocol called Firmata to communicate with the micro-controller over the USB .

Recommended:


Step 1 – Setting up Firmata to Arduino Board

Before going to start programming with NodeBots, First we need to load Firmata onto Arduino board.

  • Download Arduino IDE from it’s official website. know more about Arduino IDE visit this visit this: Arduino IDE | Arduino | Open Source Hardware/Softawre | Arduino Vs RPi
  • Connect Arduino board via USB cable
  • Launch Arduino IDE and find the Firmata sketch using the Menu -> File -> Examples -> Firmata -> StandardFirmata
  • Select your Arduino board type using Tools -> Board
  • Select the port (Comm Port) for the board using Tools -> Serial Port
  • Upload the “StandardFirmata” program by selecting File -> Upload

Step 2 – Node.js  Installation

We use Ubuntu OS. You can use any OS. For installation visit official website Node.js® web site.

Supported Ubuntu versions:

NodeSource will maintain Ubuntu distributions in active support by Canonical, including LTS and the intermediate releases.

  • Ubuntu 14.04 LTS (Trusty Tahr) – not available for Node.js 10 and later
  • Ubuntu 16.04 LTS (Xenial Xerus)
  • Ubuntu 18.04 LTS (Bionic Beaver)
  • Ubuntu 18.10 (Cosmic Cuttlefish)

Installing Node.js via package manager

Installation instructions

Node.js v11.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs

Node.js v10.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs

Node.js v8.x:

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs

To check which version of Node.js you have installed after these initial steps, type:

nodejs -v

For more information about Installation Visit This – https://iotbyhvm.ooo/how-to-install-node-js-on-ubuntu/

Installation steps for Windows

Step by step guide line

  • Download the Windows installer from the Nodes.js® web site.
  • Run the installer (the .msi file you downloaded in the previous step.)
  • Follow the prompts in the installer (Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings).
  • Restart your computer. You won’t be able to run Node.js® until you restart your computer.

Step 3 – Johnny-five Installation

  • Open Command Prompt. / Open Terminal in Linux.
  • Run the following command in CMD/Terminal
npm install johnny-five
  • Wait for installation complition.

Step 4 – Code

Open Any Text editor (Notepad, Notepad++, Nano or Vi Editor) and write below program and save it.

var led_pin=13;
var johnny_five=require("johnny-five"); 
var arduino_board=new johnny_five.Board(); 
arduino_board.on("ready", function() {  
   console.log("Blinking Program is Ready for use!");  
   var led = new johnny_five.Led(led_pin);  
   led.blink(1000);  
});

Step 5 – Connection

connection

Step 6 – Finishing up

  • Open command prompt
  • Specifies your saved file location by using cd command in command prompt
  • Run the following command
node your_file_name.js

I hope you like this post “Using Node js and Arduino with LED Blinking Program”. Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

You may like also:


 

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

2 thoughts on “Using Node js and Arduino with LED Blinking Program

Leave a Reply

Your email address will not be published. Required fields are marked *