Switch from DHT11 to DHT22 problem

OK so the video clearly shows the twitching to 0 at intervals well below 10s.

To be able to debug further we would need your current script in it’s entirety and a QR code / url for a clone of your project.

1 Like
var blynkLib = require('/usr/lib/node_modules/blynk-library');
var sensorLib = require('/usr/lib/node_modules/node-dht-sensor');

var AUTH = '249ab40a7c0b4cf5bb83982d82928bea';

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

// Setup sensor, exit if failed
var sensorType = 22; // 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(6, readout.humidity.toFixed(1));

    console.log('Temperature:', readout.temperature.toFixed(1) + '°C');
    console.log('Humidity:   ', readout.humidity.toFixed(1)    + '%');
}, 10000);

btw i was using the same setup with the DHT11 and that worked perfectly fine

Probably one of those.

hardware issue?

substitute parts to confirm or deny…

If it was a hardware issue, i would see it in the console no ? And parts are from aliexpress, like all my parts are.

put the Dht11 back in and check…

1 Like

What does the .toFixed(1) do in the data readout command?

1 Like

I don’t know, it is not my code i just changed it up.

Ah, it is referring to the decimal point:

.toFixed(deciamlPlaces): Return this number/string to the given number of decimal places. For example,
var n = 1.2345;
console.log(n.toFixed(2)); // 1.23
console.log(n); // 1.2345 - No change!

I was just wondering if removing it from the blynk.virtualWrite() would affect how the display reacts?? Besides it is not needed for the Labeled Value widget, which has it’s own decimal control.

blynk.virtualWrite(3, readout.temperature);
blynk.virtualWrite(6, readout.humidity);

Yes i was thinking the same thing but i could not figure out wich string of code controlled the decimals. Thanks alot i will try this.

So i found the problem, and i feel stupid for wasting your guys time with this. I turned it off and on again and it acted normal again…

Thanks for all yours guys time and help, im sorry it was such a stupid fix.

at least we all learned something…