Introduction: Raspberry Pi + Node.js + Blynk App + DHT11/DHT22/AM2302

Picture of Raspberry Pi + Node.js + Blynk App + DHT11/DHT22/AM2302

This time we will display some sensor values (DHT11 in example) on the Smartphone using Blynk App.
You will need:

  1. Raspberry Pi with internet connection
  2. Temperature and humidity sensors: DHT11 or DHT22 or AM2302
  3. Jumper wires

Please check my tutorial about getting Blynk and Node.JS running on Raspberry Pi and other single-board computers (BeagleBone, Intel Edison, Galileo, VoCore, OpenWrt... ):

After you get Blynk JavaScript library running, we can move on to reading sensor values.

Step 1: Install Sensor Libraries

For DHT11/DHT22/AM2302 sensors, you need to download and install:

Here are the commands I run on my Raspberry to do this (it may take some time to execute...):

tar zxvf bcm2835-1.46.tar.gz
cd bcm2835-1.46
sudo make check
sudo make install
sudo npm install -g node-dht-sensor

Note: You may want to read the node-dht-sensor Readme, and run "First Example" ;)

Step 2: Scan/create Blynk Project

Picture of Scan/create Blynk Project

After logging in to the Blynk App, you can scan the QR code and get the project I have prepared for you (only Android, for now...).

Alternatively, you can create it manually:

  1. Create a new dashboard of type Generic, and send yourself an Auth Token.
  2. Add a Graph widget and bind it to V3
    Set range to 10..40,
    reading frequency to "PUSH"
  3. Add a Value Display widget and bind it to V4
  4. Press Run (triangle in the upper right corner)

Step 3: Blynk Script for DHT11

Picture of Blynk Script for DHT11

Wire Raspberry Pi and DHT11:

  • GND to GND
  • sensor Signal to gpio4
  • sensor VCC to 3.3v

On the board, create a new file (call it blynk-sensor-test.js):

var blynkLib = require('blynk-library');
var sensorLib = require('node-dht-sensor');


// Setup Blynk
var blynk = new blynkLib.Blynk(AUTH);

// Setup sensor, exit if failed
var sensorType = 11; // 11 for DHT11, 22 for DHT22 and AM2302
var sensorPin  = 4;  // The GPIO pin number for sensor signal
if (!sensorLib.initialize(sensorType, sensorPin)) {
    console.warn('Failed to initialize sensor');

// Automatically update sensor value every 2 seconds
setInterval(function() {
    var readout =;
    blynk.virtualWrite(3, readout.temperature.toFixed(1));
    blynk.virtualWrite(4, readout.humidity.toFixed(1));
    console.log('Temperature:', readout.temperature.toFixed(1) + 'C');
    console.log('Humidity:   ', readout.humidity.toFixed(1)    + '%');
}, 2000);

Replace YOUR_AUTH_TOKEN with your token from the App.
You may also want to change sensorType and sensorPin.

Now run it:

sudo NODE_PATH=/usr/local/lib/node_modules node ./blynk-sensor-test.js

The output should look like this:

OnOff mode
Connecting to TCP: 8442
Temperature: 18.0C
Humidity:    26.0%
Temperature: 18.0C
Humidity:    26.0%


  • You need to run our script with sudo as the sensor library requires privileged access to the hardware
  • NODE_PATH=.. is set because Node.js may fail to locate global modules otherwise

Step 4: Enjoy Sensor Values in the Blynk App

Now, check the Blynk App on your smartphone, it should display a nice plot of temperature and current value of humidity. Congratulations! ;)


ealansilehto (author)2017-11-23

Help! What does it mean at this point;

On the board, create a new file (call it blynk-sensor-test.js):

var blynkLib = require('blynk-library');
var sensorLib = require('node-dht-sensor');....etc

akr6 made it! (author)2017-11-01

i changed the node-dht-sensor to rpi-dht-sensor

install it using command

sudo npm install -g rpi-dht-sensor

then run

sudo NODE_PATH=/usr/local/lib/node_modules node ./blynk-sensor-test.js

than all thing works.

akr6 (author)2017-10-31

The script works perfect

but i didn't get any data only 0.0% shows

pi@raspberrypi:~ $ sudo NODE_PATH=/usr/local/lib/node_modules node ./blynk-sensor-test.js

OnOff mode

Connecting to: 8441

SSL authorization...



Temperature: 0.0C

Humidity: 0.0%

Temperature: 0.0C

Humidity: 0.0%

Thorstenk (author)2017-09-17

The script works perfekt.

But when I use the pwm (over the app) for one LED on Pin18, I get the error:

"Illegal arguments for construction of _exports_Pwm"

and the script stops working

Can you help me?

nickpagazani (author)2016-11-04

By far one of the most frustrating things I've ever tried to do is to get my DHT22 sensor to display on anything! I've tried at least 4 different tutorials using different platforms. They all fail in one form or another. This one looked easy, but it also fails! I've installed, re-installed, read the readme's, whatever you can think of. Can you help? I'm running an RPi 2 Model B v1.1. Here's a screen shot of the result of running "the sudo npm install -g node-dht-sensor" command.

IrshatA (author)2016-10-21

Thanx. How add autostart to rc.local?

Satish Ajodha (author)2016-05-23

Excellent, thanks works like a charm!

losgat (author)2016-02-14


After following

i get

throw err;

Error: Cannot find module 'node-dht-sensor'

please help what do I do to fix this.


SURAJS56 (author)losgat2016-05-13

The problem is with node-dht-sensor 0.0.11 , However 0.0.8 works fine.

So install the package as

sudo npm install -g node-dht-sensor@0.0.8 --unsafe-perm=true

and it should work as charm.

LoganB35 (author)2016-03-27


I'm having trouble running any examples and tutorials I've tried, including this one. I keep getting the following output...

throw err;
Error: Cannot find module 'blynk-library'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/usr/local/lib/node_modules/firstjs.js:1:75)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)

any ideas or tips? :/

SURAJS56 (author)LoganB352016-05-13

Follow the steps as in

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential
sudo npm install -g npm
sudo npm install -g onoff
sudo npm install -g blynk-library

mrcoolkaran007 (author)2015-11-21

If i want to use the blynk local server, how do I enter the local server IP in

var blynk = new blynkLib.Blynk(AUTH);

I tried AUTH,"LocalServerIP" but its not working. On the blynk community page they have mentioned about Arduino but not RPI and nodeJS.

dlopina made it! (author)2015-11-04

Hey thanks for the Instructable! Worked great. This was my first time coding on the Raspberry Pi (I'm not good at baby steps). I even managed to convert Celsius to Fahrenheit.


// Automatically update sensor value every 2 seconds

setInterval(function() {

var readout =;

var tempF = ((readout.temperature.toFixed(1))*1.8))+32

blynk.virtualWrite(3, tempF);

blynk.virtualWrite(4, readout.humidity.toFixed(1));

console.log('Temperature:', tempF + 'F');

console.log('Humidity: ', readout.humidity.toFixed(1) + '%');

}, 2000);

About This Instructable




More by vshymanskyy:Raspberry Pi + Node.js + Blynk App + DHT11/DHT22/AM2302Blynk + JavaScript in 20 minutes [Raspberry Pi, Edison, Espruino ...]Control quadcopter from your phone in 30 minutes! [ESP8266 + A7105 + Blynk App for iOS/Android]
Add instructable to: