简体   繁体   中英

Arduino-DHT11 library for reading every 30 second

does any one here experienced with various dht11 library for arduino?, I want to read the temperature value every 30 second, I am using the standard library but sometimes throw me NaN. In avarege I got 2 NaN values out of 10 readings (20%).

I got many errors about many dht11 libraries, but one day finally I found a good library and good example code.

Firstly you have to download the library from this link and add this to arduino's library folder.

Secondly, you should do this pin connections

Lastly, here it is example code. It should work.

#include <dht11.h>

int DHT11_pin=2;
dht11 DHT11_sensor;

void setup()
{
  Serial.begin(9600);
  Serial.println("GOOD LUCK");
  Serial.println("*********************");
}

void loop()
{
  int chk = DHT11_sensor.read(DHT11_pin);

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11_sensor.humidity, 2);

  Serial.print("Temp (Celcius): ");
  Serial.println((float)DHT11_sensor.temperature);

  Serial.print("Temp (Kelvin): ");
  Serial.println(DHT11_sensor.kelvin(), 2);

  Serial.print("Temp (Fahrenheit): ");
  Serial.println(DHT11_sensor.fahrenheit(), 2);

  Serial.print("Dew Point: ");
  Serial.println(DHT11_sensor.dewPoint(), 2);

  Serial.println("------------------");
  delay(500);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM