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

[SOLVED] Blynk+ESP-01+DHT22 -- Failed to read from DHT sensor!


#1

Hello,

I’m trying to connect together ESP-01 and DHT22,
but after I’m uploading the code to ESP8266,

I’m always got the same repeated error after blynk was connected:

Failed to read from DHT sensor!

I’m tried to use external 3.3/5v for DHT22 but no luck.

I think the problem is in wrong PIN number for GPIO2 in my ESP-01 for DHT. Am I right?

Have no idea how to solve this problem. Please help!

Pinout:

Arduino IDE flashing params:

Code(all ext libraries is the same as links inside the code):

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  WARNING :
  For this example you'll need Adafruit DHT sensor libraries:
    https://github.com/adafruit/Adafruit_Sensor
    https://github.com/adafruit/DHT-sensor-library

  App project setup:
    Value Display widget attached to V5
    Value Display widget attached to V6
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

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

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11     // DHT 11
#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
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!");
    return;
  }
  // 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);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}


#2

What happens if you comment-out the DHT11 line and uncomment the DHT22 line instead?

Pete.


#3

Pete, I’m sorry.

You’re right – i’m use DHT22 library during getting my error, instead of DHT11,
I’ll correct my code example. Sorry for this miscommunication


#4

Now post a photo of your actual breadboard setup, rather than a fritzing diagram.

Pete.


#5

Pete,

Here is my breadboard

Original size


#6

I have an example sketch you might find interesting… adjust for your DHT12 :stuck_out_tongue_winking_eye:

It has been running stably on my desk 24/7 for most of the year now.


#7

Thanks for your help,
can you also please share your DHT lib source and show the wiring is it possible?

In my case changing GPIO2 go GPIO0 and updating the DHT PIN in the code from 2 to 0 didn’t help:(

Still got the same Failed… error


#8

I am using the Adafruit Unified Sensor Library

And I never get around to documenting wiring… I just took some pictures now, hope you can make sense of them :stuck_out_tongue: Top power rail is 3.3v bottom power rail is 5v

The loose Black wire and the level shift board are just there for the rare moments I need to pop in a TTL adapter for flashing (I normally use OTA)


#9

Okay, I find the solution myself:

You need to update your adafruit/DHT-sensor-library
DHT.cpp code with this commit:

https://raw.githubusercontent.com/adams13x13/DHT-sensor-library/761f4f4fb94c01afc283d0ffbfbfdeed5bb18a44/DHT.cpp

Then I started received T and H values instead of nan.

Yahoo!


#10

Not sure what you mean… why load in some unknown .cpp file (as your link references) instead of the official, working one - https://github.com/adafruit/Adafruit_Sensor


#11

Because official release of adafruit/DHT-sensor-library always returned me an Failed… error.

So I turned on debug option in DHT.h (uncommented #define DHT_DEBUG) and then find a topic with that commit, linked above:


#12

Ah, well that link at least tells the story… but I still wouldn’t randomly trust loading in that other link you provided :wink:

If it worked for you and adams13x13 then go for it… but strange that Adafruit didn’t acknowledge the issue or “fix”.

I wonder if the frequency you were calling (1s) could have been a factor… or the GPIO pin?
I successfully use a different pin for my ESP-01 #define DHTPIN 0 // GPIO0 - physical pin 5 on ESP-01

I will mark this solved.


#13

Well… looks like Adafruit don’t needed to add any updates about 2 yrs.

And if you don’t trust to others commits and have some programmer skills, github allows you to compare changed code with the original one:

I’m happy that you used another pin, but for me it has no difference, because original DHT lib returned Nan on any pin:(


#14

Actually it was the original link I was unsure about… clicking on it just got a txt file, and trying to step back a directory level in the browser just gave me Invalid request. But I now see the proper link, so yes, much better :wink: