DHT11 Time out error using v0.4.1library


i'm struggling dht11 sensor work on arduino. code compiles without problems in serial monitor output keep on getting " read sensor: time out error"

i've tried multiple libraries, adafruit etc still none of them worked. set serial monitor same speed (115200) didn't fix problem. 

i'm using: 

mega2560 

dht11 temp+hum sensor

windows10 x64

arduino 1.6.9

library dht11.h v0.4.1 source:  http://playground.arduino.cc/main/dht11lib

wiring : blue = gnd yellow = 2 red = 5v (also see picture) 

my code: 

 
code: [select]
#include <dht11.h>

//
//   file:  dht11_test1.pde
// purpose: dht11 library test sketch arduino
//

//celsius fahrenheit conversion
double fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

// fast integer version rounding
//int celcius2fahrenheit(int celcius)
//{
//  return (celsius * 18 + 5)/10 + 32;
//}


//celsius kelvin conversion
double kelvin(double celsius)
{
  return celsius + 273.15;
}

// dewpoint function noaa
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/geography/weather_station/geog_site/about.htm
//
double dewpoint(double celsius, double humidity)
{
  // (1) saturation vapor pressure = esgg(t)
  double ratio = 373.15 / (273.15 + celsius);
  double rhs = -7.90298 * (ratio - 1);
  rhs += 5.02808 * log10(ratio);
  rhs += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/ratio ))) - 1) ;
  rhs += 8.1328e-3 * (pow(10, (-3.49149 * (ratio - 1))) - 1) ;
  rhs += log10(1013.246);

        // factor -3 adjust units - vapor pressure svp * humidity
  double vp = pow(10, rhs - 3) * humidity;

        // (2) dewpoint = f(vapor pressure)
  double t = log(vp/0.61078);   // temp var
  return (241.88 * t) / (17.558 - t);
}

// delta max = 0.6544 wrt dewpoint()
// 6.9 x faster dewpoint()
// reference: http://en.wikipedia.org/wiki/dew_point
double dewpointfast(double celsius, double humidity)
{
  double = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
  double td = (b * temp) / (a - temp);
  return td;
}


#include <dht11.h>

dht11 dht11;

#define dht11pin 2

void setup()
{
  serial.begin(115200);
  serial.println("dht11 test program ");
  serial.print("library version: ");
  serial.println(dht11lib_version);
  serial.println();
}

void loop()
{
  serial.println("\n");

  int chk = dht11.read(dht11pin);

  serial.print("read sensor: ");
  switch (chk)
  {
    case dhtlib_ok:
    serial.println("ok");
    break;
    case dhtlib_error_checksum:
    serial.println("checksum error");
    break;
    case dhtlib_error_timeout:
    serial.println("time out error");
    break;
    default:
    serial.println("unknown error");
    break;
  }

  serial.print("humidity (%): ");
  serial.println((float)dht11.humidity, 2);

  serial.print("temperature (°c): ");
  serial.println((float)dht11.temperature, 2);

  serial.print("temperature (°f): ");
  serial.println(fahrenheit(dht11.temperature), 2);

  serial.print("temperature (°k): ");
  serial.println(kelvin(dht11.temperature), 2);

  serial.print("dew point (°c): ");
  serial.println(dewpoint(dht11.temperature, dht11.humidity));

  serial.print("dew pointfast (°c): ");
  serial.println(dewpointfast(dht11.temperature, dht11.humidity));

  delay(2000);
}
//
// end of file
//


serial monitor output: 
code: [select]
temperature (°c): 0.00
temperature (°f): 32.00
temperature (°k): 273.15
dew point (°c): nan
dew pointfast (°c): nan
dht11 test program
library version: 0.4.1


i kindly thankful if have @ least idea of wrong, 

natalie.

it hard tell how sensor wired picture.  is this?



sometimes necessary have 10k or pullup (between data , vcc).

code: [select]
#define dht11pin 2
but picture shows data going (analog) pin a2 not (digital) pin 2 next tx0.


Arduino Forum > Using Arduino > Sensors > DHT11 Time out error using v0.4.1library


arduino

Comments

Popular posts from this blog

sd card Could not find FAT16/FAT32 partition [solved]

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!