Internet of Things with JavaScript(Arduino, PubNub, Johnny_five )

Category : Internet of Things (IoT)

Internet of Things with JavaScript(Arduino, PubNub, Johnny_five )

Having worked for some time with Arduino boards, I always wondered if there was another to interact with them. Right now what I have been doing is set up Arduino Boards with led, DC motors and so on after that I uploaded a sketch to have it all worked. Although this is really interesting and asks for more, I found the action to be quite passive.


This is when I learned that with the help of Javascript and Node.js, one could built a very simple website and control the Arduino Board from there. This brings me closer to the Internet of Things , the interconnection via the Internet of computing devices ( like an Arduino Board ) embedded in everyday objects, enabling them to send and receive data. 


This is where Johnny-five (J5), a JavaScript framework to program Arduino bots comes to the rescue. Johnny-Five is an Open Source, Firmata Protocol based, IoT and Robotics programming framework. The J5 library lets you control many components of an Arduino Board. It has classes for pretty much everything, from LED to DC Motor to each and every pin within the board itself. J5 on its down does not let you control the board from a webpage . 


This is where PubNub comes into action. PubNub is a global Data Stream Network and realtime infrastructure-as-a-service company. One of the cool features this company is the Publish/Subscribe model. 


PubNub utilizes a Publish/Subscribe model for realtime data streaming and device signaling which lets you establish and maintain persistent socket connections to any device. One can publish messages to any given channel, and subscribing clients receive only messages associated with that channel. The message payload can be any JSON data including numbers, strings, arrays, and objects.


So put simply, J5 gives you access to the different components while PubNub let's you communicate between the web page ( read:  any sort of Web Application ) and the baord in itself. You want the led on, no problem. You want to start the DC Motor, turn the led on, stop the DC motor, sure that is all possible ( and a lot more ).




-Node.js is required.

-PubNub: To build an application that leverages the PubNub Data Stream, you need to sign up for your account to obtain API keys.

To get started with PubNub JavaScript APIs, you need to include the latest (or desired) version of pubnub.jsfrom CDN or locally.

-Johnny Five: Install Johnny-five using the npm package manager.

-ARDUINO IDE is required to upload the only sketch you will need. Johnny-Five communicates with Arduino using the Firmata protocol, so you need to install StandardFirmata.


One last note: This is not the only way one ca communicate with a board. There are many example out there but for now, I like to talk about things I know so I hope this would be useful for someone.

That is pretty much it. I will be publishing articles with examples so watch this blog closely.