Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Angelo Santagata
#24223 Hi all,

In going a little nutty trying to get a DHT11 sensor to work with the esp8266-12E.. I constantly get "Failed to read DHT sensor" but its setup correctly and Ive tried two sensors..

DHT11 Wiring
pin 1 : +3V
pin 2 : to GPIO 5 (D1 of NodeMCU Board) also to +3v via 10k resistor
pin 3 : Not connected
pin 4 : Gnd

Sketch is pretty basic
Code: Select all#include <DHT.h>


#define LED 4
#define DHT11SensorPin 5


DHT dht(DHT11SensorPin, DHT11);

void setup()
{

   /* add setup code here */
   Serial.begin(9600);
   Serial.println("Init");
   pinMode(LED, OUTPUT);
   dht.begin();
  delay(3000);

}

void loop()
{
   Serial.println("Loop Start");
   // Flash LED
   digitalWrite(LED, HIGH);
   delay(500);
   digitalWrite(LED, LOW);
   delay(500);
   // Read DHT11 Temp/Humidity Sensor
   // Reading temperature or humidity takes about 250 milliseconds!
   
   float h = dht.readHumidity();
   // Read temperature as Celsius (the default)
   float t = dht.readTemperature();
   // Check if any reads failed and exit early (to try again).
   if (isnan(h) || isnan(t))  {
      Serial.println("Failed to read from DHT sensor!");
      return;
   }
   // Compute heat index in Celsius(isFahreheit = false)
   float hic = dht.computeHeatIndex(t, h, false);

   Serial.print("Humidity: ");
   Serial.print(h);
   Serial.print(" %\t");
   Serial.print("Temperature: ");
   Serial.print(t);
   Serial.print(" *C ");
   
   Serial.print("Heat index: ");
   Serial.print(hic);
   Serial.print(" *C ");
   delay(3000);



}


Ive used the adafruit Library..
User avatar
By Angelo Santagata
#24224 Arrrrrgghh just as I posed this I got it working..

1. DO NOT Use the ADAFruit DHT11 library.. doesnt work
I used https://github.com/adafruit/DHT-sensor-library , just make sure
1. You delete the other libraries from the library directory.
2. Put more of a delay in reading between sensor values.. I think thats the main issue

leaving post for Noobs like me