Can not read values from node-dht-sensor

here’s the code:
var Blynk = require(‘blynk-library’);
var sensor = require(‘node-dht-sensor’);

var AUTH = ‘70c71f1d7891413a95ef84d624e49523’;

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

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

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

Although it runs OK, the temperature and the humidity value both are 0, What should I do?

One of the main reasons sensors don’t give a reading is because users don’t understand the GPIO numbering system.

What hardware are you using, what physical pin is the sensor connected to and why did you pick GPIO 1?

But when I use python, it works.

I am using raspberry pi 3B and the physical pin… I think it is 12

In that case I think you should change sensorPin from 1 to 18.

A HUGE thank you!!! problem solved!

Worth repeating.

Raspberry Pi’s have at least 3 pin numbering systems and one of the most popular ways to use the GPIO’s is with the terrific work done by Gordon Henderson in wiringPi. However for some unknown reason he chose a totally different numbering system for wiringPi and as he refers to them as GPIO 1, GPIO 2 etc many users think they require these numbers for all Pi projects.

The official numbering system is the BCM numbers, not wiringPi numbers.

A full 40 pin interactive pinout diagram is available at https://pinout.xyz/

If you hover over the pins it will show the wiringPi GPIO reference but they are only used if you are using wiringPi routines, all other routines use the official BCM references.