Blynk + JavaScript in 20 minutes

Learn how to use Blynk with Node.js on a variety of platforms.

Categories: Intermediate

Ever wanted to control "some THING" from your smartphone?

Now it’s really easy.
is a universal remote control, that can also display and plot data (and works over internet). It makes prototyping Internet of Things applications so easy, that many people call it "
IoT on-the-go

For example, this is how to
control a quad-copter from your phone (in 30 minutes!)

Also, here is
the official documentation

Blynk is supporting
of prototyping
hardware platforms and configurations.
 And it has released a
Node.js / Espruino
module recently, so now it can also be used on:

  • Regular computers with Windows/Linux/OS X
  • Single-board computers like Edison, Raspberry Pi, Beagle Bone,…
  • OpenWrt – based routers and boards like VoCore,Carambola, TL-MR3020
  • Espruino – compatible microcontrollers

This is a
nice and strong addition to
the list of supported platforms.

Today I’m going to show you some simple steps how to start Blynking using JavaScript. Before we start, we need to do few preparation steps:

  • Check if JavaScript is installed on your device

Step 1: Node.js and Blynk installation

Check if Node.js is installed.

Open the console (terminal) on your board and type:

node --version


nodejs --version

You should see something like:


If it doesn’t print the version or shows an error, please follow Node.js installation guide for your platform. I’ll give you some hints:

Raspberry Pi / BeagleBone

Check that your board is connected to the internet, run in it’s terminal:

curl -sL | sudo -E bash -

The previous command updates our package repository to include the required packages. Now, let’s install
and Blynk!

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install -y build-essential nodejs

sudo npm install -g npm

sudo npm install -g onoff

sudo npm install -g blynk-library

OpenWRT (VoCore, Carambola, WRTnode, TL-MR3020…)

I was able to run it on VoCore, it should also be easy to do it on other OpenWrt-based computers. Everything I needed was to add Espruino package to my OpenWrt source and build it:…

For OpenWrt you can start with this example:…

Intel Edison

Node.js should be already there… Just follow the Getting Started guide:…

After verifying the Node.js is on your board, and the board is connected to the internet, run:

npm install -g mraa blynk-library

Intel Galileo

You will need to use an SD card that contains the latest Intel® IoT Developer Kit image, and use USB-to-UART to access it:

After verifying the Node.js is on your board, and the board is connected to the internet, run:

npm install -g mraa blynk-library

Espruino Pico

Did you notice that tiny micro-controller running JS?

It has no internet connectivity out-of-the box, but you can add a cheap ESP8266 to get it:

(There are other options, read here:

After establishing internet connection, you can start with this example:…

Other boards,PC with Linux, Windows …

Just google how to install Node.js 😉

Then run in the console:

npm install -g blynk-library


npm install command might fail on your board, saying something like this (I got this on Galileo):


In this case, you just need to update time on your system using
command 🙂

Note that on some boards, the default direct pin control won’t work.But you are always free to do
ANYTHING you want using Virtual Pins

We have prepared the environment, and now it is time to play!

Step 2: Writing a simple script

In the Blynk mobile App:

  • Create a new dashboard of type
    , and send yourself an
    Auth Token
  • Add a
    Value Display
    widget and bind it to
  • Add a
    widget and bind it to
  • Press
    (triangle in the upper right corner)

Let’s check simple built-in test script.


environment variable should point to the place where npm stores globally installed modules. If you get something like "
Error: Cannot find module blynk-library
", you should run in the console (the path might be different):

export NODE_PATH=/usr/local/lib/node_modules

Now, run on your board (put your auth token):

blynk-client 715f8cafe95f4a91bae319d0376caa8c

It should print something like:

Connecting to SSL: 8441

Connected, authorized

Blynk ready.

to exit.

If it doesn’t work, check if:

  • you used a correct auth-token from your mobile project
  • internet connection is OK
  • simple Node.js scripts work

Usually there should be no problems.

Now let’s write our own script.

TCP connection

First try a TCP connection example. It is insecure, but easier to start.

On the board, create a new file (call it

var Blynk = require('blynk-library');


var blynk = new Blynk.Blynk(AUTH, options = {

 connector : new Blynk.TcpClient()


var v1 = new blynk.VirtualPin(1);

var v9 = new blynk.VirtualPin(9);

v1.on('write', function(param) {

 console.log('V1:', param[0]);


v9.on('read', function() {

 v9.write(new Date().getSeconds());


with your token from the App.

There are two Virtual Pins specified here:
. These are actions for your widgets.

When you run the script, the project on your phone should start working:

  • The
    Value Display
    widget should show current time seconds.
  • Moving a
    should make script printing current value.

Also, if
package is installed, you should be able to read/write digital pins

SSL connection (default)

var Blynk = require('blynk-library');


var blynk = new Blynk.Blynk(AUTH);

var v1 = new blynk.VirtualPin(1);

var v9 = new blynk.VirtualPin(9);

v1.on('write', function(param) {

 console.log('V1:', param[0]);


v9.on('read', function() {

 v9.write(new Date().getSeconds());


It should work same way, but use a secured connection.

For more examples, check this folder:…

Now you’re ready to start exploring Blynk widgets and features 🙂

Step 3: Adding a Terminal widget

For example, let’s add a
widget to you phone project and bind it to virtual pin
.In your script, add these lines:

var term = new blynk.WidgetTerminal(3);

term.on('write', function(data) {

 term.write('You wrote:' + data + '\n');

 blynk.notify("HAHA! " + data);


Every time you input text into terminal, it will send it back and also push you a notification!
Note, that it won’t send you more than 1 notification per minute…You can also:

  • Send tweets and e-mails
  • Plot & store hardware sensor data
  • Bind phone App controls to any actions on the script side
  • Control Arduino and other prototyping platforms
  • Get phone sensor data (soon)
  • and much more!

Next time, I will explain how to use Virtual Pins to do PWM and read advanced sensor data.

Hope you enjoyed it.. Waiting for your comments and suggestions how to improve the article.And happy Blynking! 😉

Comments are not currently available for this post.