Volodymyr Shymanskyy
Published © CC BY-NC-SA

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

Display sensor values (DHT11 in example) on the Smartphone using Blynk App.

EasyFull instructions provided7,214
Raspberry Pi + Node.js + Blynk App + DHT11/DHT22/AM2302

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1

Software apps and online services

Blynk
Blynk

Story

Read more

Code

node-dht-sensor installation

Textile
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.46.tar.gz
tar zxvf bcm2835-1.46.tar.gz
cd bcm2835-1.46
./configure
make
sudo make check
sudo make install
sudo npm install -g node-dht-sensor

Script code

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

var AUTH = 'YOUR_AUTH_TOKEN';

// 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');
    process.exit(1);
}

// Automatically update sensor value every 2 seconds
setInterval(function() {
    var readout = sensorLib.read();
    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);

Run the script

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

Script output

Plain text
OnOff mode
Connecting to TCP: cloud.blynk.cc 8442
Connected
Temperature: 18.0C
Humidity:    26.0%
Temperature: 18.0C
Humidity:    26.0%

Github

https://github.com/vshymanskyy/blynk-library-js

Github

https://github.com/momenso/node-dht-sensor

Credits

Volodymyr Shymanskyy

Volodymyr Shymanskyy

3 projects • 32 followers
Co-founder of Blynk, Dreamer And Doer, Public Speaker

Comments

Add projectSign up / Login