Switch from DHT11 to DHT22 problem

Hi, so today my DHT22 arrived and i switched it out with the old DHT11 and its much better.I also switched my code from DHT22 to DHT11. Now here is the problem, maybe better to illustrate it with a graph !

So on the second graph you see i get data,zero,data,zero. I did not have this with the DHT11.
Il add the code here, maybe i missed something ?
Thanks in advance guys.

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

    var AUTH = 'xxx';

    // 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(5, readout.temperature.toFixed(1));
        blynk.virtualWrite(4, readout.humidity.toFixed(1));
        blynk.virtualWrite(6, readout.humidity.toFixed(1));

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

The hardware is rpi.

look at your wiring if you think you updated your code correctly.
what does it say in console

1 Like

Wiring is correct and console behaves like usual, just giving the data like it did before.

Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%
Temperature: 21.9°C
Humidity: 38.5%

This is how my console looks like. No 0 to be found.

@Dema323 have you set the update frequency of the display widgets to PUSH in the app?

1 Like

I tried to put it on PUSH and 1sec and result is the same. Its almost like its getting data saying its 0 but in the console you can see thats not true.

How about everything else in the app? Can you confirm if it is just the DHT data that is not showing and the other widgets are functioning?

Is that the entire code your have shown?

Everythibg is working as it used to.But its not that i don’t get any data from the dht22 its just in stead of just showing like 22 degrees is goes 22,0,22,22,22,0,22,22,0,22 like this. Zero just jumps in from time to time and that does not happen in the console. The graph shows this better

There appears to be a debugging and trace option within the node-dht-sensor library… perhaps try that and see what data that spits out?

1 Like

Hey thanks i will try that. And if that doesn’t fix it i will just try an esp8266 and see if i have te same problems.

As you have the virtualWrite’s in your script you MUST set the frequency as PUSH.

You can only use 1, 2 , 3 seconds etc if you are not using virtualWrite’s in the script and even if you didn’t have them 1 second would be a bad choice.

Your script comment states 2 second intervals but the actual script shows 3000ms, try at 10000ms.

1 Like

Good to know but it is set as push and i get the same result. I will try to set it at 10sec.

Not in the app though, just in the script.

Yes haha

So i switched it to 10s and the console shows data every 10 seconds, but in Blynk it switches from (in this case) 18.7 to 0 and 18.6 etc while console is not transmitting any data. I’m gonna try that other solution now.

That suggests you still have some widget set with a timed frequency in the app and that the reading frequency is too short for the DHT. Check all widgets and set them all as PUSH frequency.

Nope its all on PUSH, only 2 widgets

How long is it taking to show the sequence 18.7, 0, 18.6?

You say 2 widgets but your script shows at least 4 virtual pins i.e. 3, 4, 5 and 6, how come?

https://www.youtube.com/watch?v=7-Q0VMRAD-8
This will be better then any explanation i could give. And yes i added 4 because at some point i needed 4. Btw removed those aswel to see if that would help but it didn’t.

Btw the video is with everything on PUSH and the code set to 10 sec.