Post topics, source code that relate to the Arduino Platform

User avatar
By Hydro
#41592 Hi

I try to use esp12e (not node mcu) with DHT22. This is my setup :

GND -> GND
GPIO15 -> 10k + GND
GPIO2 -> DHT DATA
GPIO0 -> 10k + 3.3V
RST -> 10k + 3.3V
EN -> 10k + 3.3V
VCC-> 3.3V

And my code :

Code: Select all#include "DHT.h"

#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

char str_humi[6];
char str_temp[6];
int interval;
char piece[11];

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();

}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  dtostrf(t, 4, 2, str_temp);
  dtostrf(h, 4, 2, str_humi);
 
    Serial.println(str_temp);

}



This code works well with my esp01 but with esp12e i can't read the DHT, i always have "Failed to read from DHT sensor!
".

I try every pin but can't get the temp, always this message or nothing at all.

Maybe i miss something ?

Thank
User avatar
By stex2005
#41598 Sometimes when i'm using my DHT22 I have the same problem.
Try to check DHT's power supply and remember that if you are using a NodeMCU pin 2 is not D2.
Try to use the example code you can find in the library DHT.h on GitHub