BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

2147483647 value intermittend, DHT11 NodeMCU and Blynk

Hi, I am new at this, so please be gentle :wink:

I am getting about 80% of my readings from the DHT11 sensor as 2147483647, the other 20% or so it shows the actual temperature and Humidity.
I have now adapted the code to ‘catch’ the 2147… value before it gets to Blynk as it screws up the graph.
Any ideas what might cause this/ what I’m doing wrong?
I have the following code:
(the ‘#define Dx’ lines of the pins I copied in after a remark on another post regarding the pin numbers and actual GPIO numbers. they might be redundant.)

I have tried another NodeMCU, checked connections etc. Only thing not done is replace the DHT11 sensor (waiting for delivery of that one).

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define D0 16
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as "LED_BUILTIN", but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO 
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0 (Serial console)
#define DHTPIN 0 // The pin you connect to, 0 = D3
#define DHTTYPE DHT11   // DHT 11 Change this if you have a DHT22
DHT dht(DHTPIN, DHTTYPE,16); // Change this to 

SimpleTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "11111"; // your token here
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "ssid", "password");
  timer.setInterval(30000, sendDHT);
}

void sendDHT()
{
//Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  int hum = (int) h;
  int tem = (int) t;
//Write values to V04 and V05, blocking 2147483647 value
if (hum == 2147483647) {
  Serial.print(" false hum reading ");
} else {
  Blynk.virtualWrite(4, hum);
}
if (tem == 2147483647) {
  Serial.print(" false humtemp reading ");
} else {
  Blynk.virtualWrite(5, tem);
}

  Serial.print(hum);
  Serial.print(" percent  \n\r");
  Serial.print(tem);
  Serial.print(" celcius  \n\r");
}
void loop()
{
  Blynk.run();
  timer.run();
}

end of code.
Part of the serial output:

false hum reading false humtemp reading 2147483647 percent
2147483647 celcius
false hum reading false humtemp reading 2147483647 percent
2147483647 celcius
false hum reading false humtemp reading 2147483647 percent
2147483647 celcius
false hum reading false humtemp reading 2147483647 percent
2147483647 celcius
false hum reading false humtemp reading 2147483647 percent
2147483647 celcius
30 percent
21 celcius
false hum reading false humtemp reading 2147483647 percent
2147483647 celcius
false hum reading false humtemp reading 2147483647 percent
2147483647 celcius
30 percent
21 celcius
31 percent
21 celcius

Code snippets should be formatted. Edit your post

Wrap the code by adding 3 Backtick: ``` symbols:

Example:

 ``` cpp <--put 3 backticks BEFORE your code starts  (cpp means C++ language) 

   //Put your code here
   //..................
   //..................

 ``` <--insert 3 backticks AFTER your code

**This makes your code readable and with highlighted syntax, like this:**
//comment goes here 
void helloWorld() { 
   String message =  "hello" + "world"; 
}

Apologies Pavel.
Edited the post to comply.

I’m still very new to all of this too, but a quick google search showed that 2147483647 is the max int value of a 32 bit number. This link also came up and may have some useful info. This also looks like a very helpful link as it has code, wiring, etc. After a quick scan of the thread it looks like a few things may be at fault:

  • Something related to the timing of the readings.

  • Using an incorrect pull-up resistor

  • Something related to the esp8266 itself. If you have an Uno or something else, you may be able to try and use that.

Hopefully one of the solutions offered in the thread helps! Let us know how it goes. I was just considering picking up a few DHT11s or DHT22s for a project.

This is an example of my code for reading the DHT-11 and filtered non-applied reading (“nan”):

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (!isnan(t) && !isnan(h)) {
    Blynk.virtualWrite(VDisplayTemp, t);
    Blynk.virtualWrite(VDisplayHumid, h);
    DHT11_working = 1;
  }
  else {
    DHT11_working = 0;
  }

The DHT11_working variable is then to be used to set Virtual LED to indicate whether DHT-11 is working or not
And also, on the hardware side, put a pullup resistor between VCC and Data Pin.

Also to be save set the reading every (at the minimum) 6 seconds (I found several differences in the specs), http://robocraft.ru/files/datasheet/DHT11.pdf showing 6 seconds

Hi,
How Long is the cable?
Use resisistor directly before sensor, capacitor will stabilize readings aswell just before sensor.
Second thing try with different library, I’m using DHT by Rob Tillaart it is much stable than adafruit.

Instead of converting float to int, just send the float value or use “Int temp = dht.huumidity()” or whatever. (I’m on a phone so I can’t see the actual code you have right now). That’s what I do and it seems to work. Best regards

Hi, thanks. A different (better?) way of filtering bad readings, but what I’m trying to get are more good readings. There shouldn’t be that many false readings to begin with.
The pullup resistor is there. Originally 4k7 when connected to 5V. With the 3.3V supply I tried 3k3 and 10k (as I found that in another diagram).
The delay between readings is 30 Seconds, so that should be enough.

Is there a way of having the actual ‘read’ take longer (so, having the read take a second before passing the value on) or is it reading all the time, just transferring the reading every 30 seconds. (does this make sense?)
Cheers.

Elgato, the cable is about 10cm. the sensor is on a breadboard next to the NodeMCU.
I still have to try a different library.
Also still waiting for the new DHT11 and 22 to come in, as that would at least rule out a faulty sensor.

Try the rob tillaart library!

you using “breadboard”? Try hard-wiring!

You using “perfboard”? Try designing PCBs!

Think I made my last PCB about 36 years ago hjroh0315 (yep, showing my age here :grinning:) Am an old fart that grew up using Basic and a ZX81.
But the hard-wiring option came up in my mind as well Dave1829
In the mean time I borrowed an Uno and that runs (without WiFi though) showing no ‘2147…’
So guess that rules out the sensor as the problem. Must be something to do with the NodeMCU / DHT11 combo.

Really no one else has had this problem???

nup.

looks like hardware error.

what happened when you tried the library that a few people recommended?

http://playground.arduino.cc/Main/DHTLib

Hi Ron. Are you still having this problem? I am experiencing it continuously with my DHT11 sensor. I’m not sure but I may have blown my sensor when I hooked GND to the INPUT pin (off fart/old eyes). Anyway I was wondering if you were able to resolve the similar problem you were having.

@ronvsanten was last seen on the forum on Sep 23, 2016, so I doubt that you’ll get a reply (and even if you do, he may not be able to remember the solution he came-up with almost 4 years later :thinking:).

It does sound like you sensor may be damaged. If so, I’d suggest that you order a different type of sensor when you come to replace it. The DHT11 is old, extremely inaccurate, and slow. The DHT22 is slightly newer, but isn’t much better.

My preference is the BME280 (not to be confused with the BMP280, which doesn’t read humidity), but it depends on your requirements. Using a different type of sensor would obviously require some code changes.

When it comes to trying to get your existing sensor working, are you sure you’ve connected it to the correct pins on your board? If you’re using a NodeMCU then the numbering printed on the board can be confusing.
For example, if you use the Sketch Builder example here:
https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=More%2FDHT11

it contains this line:

#define DHTPIN 2          // What digital pin we're connected to

This tells the code that the ‘signal’ pin of the sensor will be connected to GPIO2 on your board. GPIO2 and the pin marked D2 on the NodeMCU are not the same thing.
GPIO2 is the pin that’s labelled D4 on the NodeMCU…

Pete.

Hi, sorry but just like @PeteKnight mentioned I have no idea if I ever fixed the issue. I have moved onto other pastures (Hassio and ESP).
Thanks @PeteKnight for following up on this.
Cheers, Ron.

1 Like

Hi Pete! Thanks for responding. I had been using my NANO 33 with my DHT11 and as I was running out of troubleshooting options I connected the DHT11 to my UNO; using the same code it worked! Hooked everything back to the NANO and the serial output displayed the 2147483647 again. Other sketches work on my NANO, but I may have fried something related to processing input information when soldering on the headers. Thankfully they are cheap enough to replace and I will grab a BME280 as well.

None the less, I really do appreciate your suggestions. Thank you.