Notifications
Clear all

Unable to get DHT11 sensor working with ESP8266

2 Posts
1 Users
0 Likes
729 Views
(@yurkshirelad)
Member
Joined: 3 years ago
Posts: 493
Topic starter  

I'm trying to get a DHT11 sensor working with an ESP8266 board. I've already confirmed the sensor works with the Uno so I know its pins.

The output on the serial monitor is:

15:21:46.800 -> TIMEOUT nan nan nan nan nan

The code is:

 

#include "DHTesp.h"

DHTesp dht;

void setup( )
{
  Serial.begin( 9600);

  dht.setup(12, DHTesp::DHT11);
}

void loop() {

  delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();

  Serial.print(dht.getStatusString());
  Serial.print("\t");
  Serial.print(humidity, 1);
  Serial.print("\t\t");
  Serial.print(temperature, 1);
  Serial.print("\t\t");
  Serial.print(dht.toFahrenheit(temperature), 1);
  Serial.print("\t\t");
  Serial.print(dht.computeHeatIndex(temperature, humidity, false), 1);
  Serial.print("\t\t");
  Serial.println(dht.computeHeatIndex(dht.toFahrenheit(temperature), humidity, true), 1);
  delay(2000);
}

I have the data line connected to GPIO12 (D6) on the ESP8266.

I got this source from the example on the library's site - https://github.com/beegee-tokyo/DHTesp/blob/master/examples/DHT_ESP8266/DHT_ESP8266.ino

 Any suggestions appreciated.

Thanks


   
Quote
(@yurkshirelad)
Member
Joined: 3 years ago
Posts: 493
Topic starter  

I switched to a different library (one that didn't work for me last night) changed the code, and it works. Strange - it's one of those days I guess!


   
ReplyQuote