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
#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..