DHT11 Time out error using v0.4.1library

I'm struggling to get the DHT11 sensor to work on Arduino. My code compiles without any problems but in the serial monitor the output I keep on getting is " Read sensor: Time out error"

I've tried multiple libraries, from Adafruit etc but still none of them worked. I also set the serial monitor to the same speed (115200) but it didn’t fix the problem.

I'm using:

Mega2560

DHT11 Temp+Hum sensor

Windows10 x64

Arduino 1.6.9

Library DHT11.h v0.4.1 source: Arduino Playground - DHT11Lib

Wiring : Blue = GND Yellow = 2 Red = 5V (Also see the picture)

My code:

#include <dht11.h>

// 
//   FILE:  dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

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


//Celsius to 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 is to 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 than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 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:

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 will be kindly thankful If you have at least an idea of what could be wrong,

Natalie.

It is really hard to tell how the sensor is wired from your picture. Is it like this?

dht11 pins.jpg

Sometimes it is necessary to have a 10K or so pullup (between data and Vcc).

#define DHT11PIN 2

But your picture shows data going to (analog) pin A2 not (digital) pin 2 next to TX0.

I am using this sensor and it has only three pins (see picture "DHT11" attached)
So I changed the data pin to digital pin 2 (see picture "new wiring" attached)
So the output I keep on getting is the same (picture attached)
Could it be a hardware problem?
Thank you so much.

Is this the module that you have? If not, please provide a photo of your module (view like the one posted that shows pins and markings)?

Did you get that dht library from the Arduino Playground?

I connected a DHT11 sensor to an Uno running the code that you posted using the library from the Playground (that I linked) and got the following result.

Read sensor: OK
Humidity (%): 34.00
Temperature (°C): 24.00
Temperature (°F): 75.20
Temperature (°K): 297.15
Dew Point (°C): 7.19
Dew PointFast (°C): 7.16

The output looks good, so the library and your code are good. That leaves a hardware problem, I guess.
FYI, in the future when posting code using a library not included with the IDE, please provide a link to the library.

Thank you so much for taking time to get back to me and test this.

So this is the module I am using, it looks really similar so I guess there is no difference (picture attached)
And yes, I am using the arduino playground library, just to make sure here is the link Arduino Playground - HomePage on

So could it be the problem with Arduino Mega2560? Or the sensor itself?

My friend is giving me an Uno and Nano boards tomorrow and I will check if the sensor works with them, if that fails then we will know that it is the sensor itself.

Also, can I have a look at your wiring or could you describe to me how you connected it just in case?

Thank you again.

The picture did not make it. I have a 4 pin DHT11 connected Vcc to 5V, Gnd to Gnd and data to pin 2 with a 10K pullup resistor from data to Vcc (refer to the 4 pin picture I posted). If your module is like the one pictured, the pullup seems to be on the board so you should not need one. That module would, I believe, be wired, + to Vcc, - to gnd and S to pin 2.

here is the picture

So it looks like you wired it right. It is not like the one that I pictured. Yours does have the pullup, that's good. If you decide to get a new one I would recommend the DHT22 instead. My experience is that the DHT22 is worth the extra cost. The DHT22 seems more responsive and accurate over the humidity range.

So I used an Arduino Uno today instead of Arduino Mega and unfortunately still getting the same "Time out error" therefore this leaves us with only one thing that could be wrong - DHT11.
Since code worked perfectly, library was good too, and the board is not a problem.
I will buy a DHT22 sensor and post the results.
Thank you for finding time to help me.

For the future readers of this topic.
I fixed the problem by purchasing a new DHT22 module.
Source fro the library and code : Arduino Playground - DHTLib
Everything worked well and I received a valid output.

Glad to hear that you got it working. We don't often get bad parts so it is the last thing we blame.

Hello,
I had same problem with DHT11.
I had Sensor with 3 pin on small board with pull up resistor.
My sensor heaven't solidered center pin ( in my its signal pin).
After solidering the pin everything works.
It is worth to check before it will go to bin:)