WeMos D1 Cannot Read DHT 11. Help!

Hi Guys, I am trying to connect the temperature DHT11 with NodeMcu then read the temperature on Blynk. Basically trying to do the same thing as this: https://community.blynk.cc/t/solved-4-pin-dht11-sensor-fail-to-read-from-dht-sensor-in-node-mcu-blynk-app/14206. I also have the same wiring, and I am using the following code:

 #define BLYNK_PRINT Serial
 #include <ESP8266WiFi.h>
 #include <BlynkSimpleEsp8266.h>
 #include <DHT.h>

char auth[] = "fdb435043f2e481696f2f8761de71c67";
char ssid[] = "emmmm1";
char pass[] = "0918260720";

#define DHTPIN 2          // What digital pin we're connected to
#define DHTTYPE DHT11     // DHT 11

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

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;
  }
  
  Serial.println("Humidity: ");
  Serial.print(h);
  Serial.print(" %, Temp: ");
  Serial.print(t);
  Serial.println(" Celsius");
  delay(1000); //Delay 1 sec.
  
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void setup()
{
  Serial.begin(115200); // See the connection status in Serial Monitor
  Blynk.begin(auth, ssid, pass);

  dht.begin();
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}

This is the output from Serial Monitor:

This seems the NodeMcu is not connecting with my WIFI and Blynk. Please help!!!

It’s not up to code, check your wifi signal strength.

Maybe you are using ESP8266 2.3.0 core for Arduino IDE? Because if you are, that would explain it. Details here:

https://community.blynk.cc/t/wpa2-compromised-upgrade-all-hardware/18353/15

If not, then try this, maybe it will work. But I still think it’s not code related.

Add:

char server[] = "blynk-cloud.com";

Replace this:

Blynk.begin(auth, ssid, pass);

with this:

Blynk.begin(auth, ssid, pass, server, 8442);

What kind of power supply are you using for NodeMCU?

Thanks for replying. I tried both methods you mentioned above, but neither of them worked. The power supply I am using is the USB cable for Android phones.

Also, when I compiled and uploaded the code, this message in showed up in red:“Archiving built core (caching) in: C:\Users\panyu\AppData\Local\Temp\arduino_cache_219869\core\core_esp8266_esp8266_d1_mini_CpuFrequency_80,UploadSpeed_115200,FlashSize_4M3M_9755e03b568b2dfea811c71b788829cf.a
S”. I dont understand what this means.

This message is telling you upload details, it’s not warning message. And it seems you specified Wemos mini D1 instead of NodeMCU, so try chosing proper board before uploading.

Once again, what’s your Ardiuino ESP8266 core version? Go to tools->boards->boards manager, then scroll down to the end of the list. There you will find esp8266 by esp8266 community version x.x.x. Read that number for me.

No, power supply you are using is certainly not USB cable for Android phones, as it has to be attached to something. I need to know what that something is.

Thank you! My device(WeMos D1)finally connects with Blynk through WiFi.:grin:
However, when I hooked up the DHT 11 temperature sensor like this:


The sensor gives me no readings. This is my sample output:
Humidity: nan %, Temp: 0.00 Celsius
My Code:

#define BLYNK_PRINT Serial
#include <SPI.h>
#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[] = "fdb435043f2e481696f2f8761de71c67";
char server[] = "blynk-cloud.com";
char ssid[] = "TC8715D5F";
char pass[] = "TC8715D14845F";

#define DHTPIN 4         // What digital pin we're connected to
#define DHTTYPE DHT11     // DHT 11
 
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

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

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %, Temp: ");
  Serial.print(t);
  Serial.println(" Celsius");
  delay(2000); //Delay 2 sec.
  
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}
 
void setup()
{
  Serial.begin(115200);
  Serial.println("Debug1");
  Blynk.begin(auth, ssid, pass, server, 8442);
  dht.begin();
  Serial.println("Debug2");
  timer.setInterval(2000L, sendSensor);
}
 
void loop()
{
  Blynk.run();
  timer.run();
}

Thank you again in advance!

Get rid of this delay… you already have the timer set for a 2 second cycle, thus that sendSensor() function keeps restarting from the beginning before it gets to the Blynk.virtualWrite() … And even 2 seconds on the timer is too fast for the DHT11, perhaps change the timer to 5 seconds.

Thank you for replying.:grin: I changed the timer to 5 seconds, but it’s still not working. I am suspecting if I reading a wrong pin, but based on this: https://github.com/esp8266/Arduino/blob/master/variants/d1_mini/pins_arduino.h#L49-L61, D2 of the WeMos is Pin 4, right?

Don’t forget to remove that delay

I don’t know… there is also two revisions of that board. So simply try each pin config until it works :wink:

I tried to read from Pin 0,2,4 and even 16, some of them give me 255 as temperature(which is definitely wrong) and the rest of them still give me no readings.:sob:

Repost your current code. Along with Serial Monitor output.

I double checked, and this is for the D1 Mini… probably not the same pinouts for your board.

Code:

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
    
char auth[] = "fdb435043f2e481696f2f8761de71c67";
char server[] = "blynk-cloud.com";
char ssid[] = "TC8715D5F";
char pass[] = "TC8715D14845F";

#define DHTPIN 4         // What digital pin we're connected to
#define DHTTYPE DHT11     // DHT 11
 
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

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

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %, Temp: ");
  Serial.print(t);
  Serial.println(" Celsius"); 
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}
 
void setup()
{
  Serial.begin(115200);
  Serial.println("Debug1");
  Blynk.begin(auth, ssid, pass, server, 8442);
  dht.begin();
  timer.setInterval(5000L, sendSensor);
}
 
void loop()
{
  Blynk.run();
  timer.run();
}

Serial Monitor:

I think this is the same one as I am using: http://cyaninfinite.com/tutorials/getting-started-with-the-wemos-d1-esp8266-wifi-board/, which also says D2 is Pin 4, but it just doesn’t work on my side.:expressionless:

You say you have tried with pin 2?

Yes, it gave me the same output on Serial Monitor. So sad.

Well, I don’t know the revision of your board… but I think pn 2 is the correct designation… try changing to another physical pin, say D8 with pin 8 in your sketch.

I also found this similar diagram… and noticed something else that I missed in the above diagram. that pin is also referenced as D0 in the R2 revision… so maybe you have a mislabeled board… long stretch, but well… try pin 0 in your sketch just for fun :smiley:

EDIT - looks like you may have already tried that.