DHT11 reads funny values

I read real funny numbers on Blynk from DHT11 connected to my ESP8266. It switches back and forth from normal readings to null, and unrealistic values like -13 degrees and 156 humidty. Please see captured video below:

Until now I’ve tried,

  • Changing the code several times
  • Changing several sensors
  • Changing power source and cables

• Device is: ESP8266 thru wifi
• Smartphone is Samsung Note 8
• Blynk server
• Latest Blynk Library version

#ifdef __AVR__
#include <avr/power.h>
#define PIN            14 //D5
#define NUMPIXELS      2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>

#include <DHT.h>
#define DHTPIN 12   //D6
#define DHTTYPE DHT11
float humidity, temp_f; 

int sensor_light = 13;  //D7
int value_light;

int sensor_water = A0;  //A0 analog input
int value_water;

char auth[] = "XXXXX"; //enter blynk auth token

#include <SimpleTimer.h>
SimpleTimer timer;

void temp_humid(){
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Blynk.virtualWrite(1, t);        //V1
  Blynk.virtualWrite(2, h);        //V2

void setup() {
  //Serial.begin(9600);         //delete serial comments when troubleshoot is necessary
  Blynk.begin(auth, "YYYYY", "ZZZZ");  //enter pot2 location wifi name & password
  pinMode(sensor_light, INPUT);
  timer.setInterval(1000, temp_humid);  //for more than 3times/day, each time about 60seconds. wake up just to get readings from all sensors
}                             //3 times, 20seconds apart. go to deep sleep, wake up8hrs later, do the same for 60seconds...

void loop() {;;

I’d try reading the sensor less frequently, as one reading per second is the upper limit for the DHT11.
It would also be good to include the isnan filtering code below to remove readings where the result isn’t a number…

void sendSensor()
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);

Alternatively, you could throw away the DHT11 and use a BME280 instead, much more reliable and accurate.


1 Like

Thanks a lot Pete!!

I already was reading within 5 sec intervals, but just placing the isnan code “mostly” solved the issue. The readings go crazy every 15-20 seconds or so. Which is good enough for me thanks.

And thanks againg for BME280 suggestion