(DHT11) Incorrect temperature and humidity reading

Below is the code I am using for reading temperature and humidity from DHT11 sensor through NodeMCU board. I see 2.1474e+09 values in my both temperature and humidity gauges, my data from DHT11 is plugged into D4 pin. Can anyone help please?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 2 // The pin you connect to
#define DHTTYPE DHT11   // DHT 11 Change this if you have a DHT22
DHT dht(DHTPIN, DHTTYPE); // Change this to 

SimpleTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "my project id";
void setup()
  Blynk.begin(auth, "my ID", "my PWD");
  timer.setInterval(100, 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
  Blynk.virtualWrite(4, hum);
  Blynk.virtualWrite(5, tem);
void loop()

Attached is the display I see in my Blynk project.

First. please read up on how to properly post code in the forum.

Secondly, have you tried simply searching?.. there is a metric ton of examples in this forum alone :wink:

You just might even find an example in the >LINK HERE example browser<… cleverly named More/DHT11 :wink:

Thanks for the advice on how to post code. Will make sure to follow the those rules next time

not only next time, you should edit your post and format the code.
how long is the wire between the dht and mcu?

ah, and this is not very clever…
these are very slow sensors, if you read the sensor datasheet, you will see, that the max sampling rate is ~1500 millis for dht11, and ~2500 millis for dht22. and you have to use pullup resistor with them.

btw, dht11 are junk sensor, no one should use them, they have very low percision. in some of my tests, among 4 dht11 sensors i measured 5 degrees celsius difference in readings!! and as humidity is also calculated based on temperature, humidity readings are also wrong. dht22 are much better, but for maximum accuracy i would reccomend bme280 or similar sensors.

1 Like

Yay!!! It works now, I was missing the pull-up resistor also changed the sampling rate 2000 millis. Not sure which one of this worked the magic.
Really appreciate the help. Thank you very much!!!

you’re welcome!
conclusion: it’s always worths reading the official datasheet.

but you still didn’t formatted your code in the very beginning of this topic. please do it so. it is very ugly this way! (you have an edit button at the bottom of your post)

1 Like

I did try to edit the code before I posted my earlier reply, but in the edit window it shows good, but in the preview it turns into bold and huge text. If that doesn’t sound right, I can post a screenshot of what I’m talking about

i know what are you talking about. it is some kind of bug in the editor.

try to remove (delete) all the code, then copy / paste again from arduino ide.
it is important to insert an empty line before and after the code here in the editor. then select all the code and click the “<<>>” button. it should be ok then.

or try the method described here: [README] Welcome to Blynk Community!

I did it, thanks for educating me. The method described in the link worked.