DHT11 Sensor giving 400C+ readings

Hi
I downloaded the recommended DHT11 library and I am using the recommended DHT11 test sketch. However I am getting extremely high results: 400C+ and 1300% humidity+, also the sensor crashes about half of the time. Pin1 = 5V with a 10k Pull resistor connecting to pin2. Pin2 = Connected to digital pin 53. Pin3 = NC. Pin4 = GND. I don't know if this is a common problem or how to fix it. Thanks in advance :slight_smile:

Please post your code, using [nobbc][code][/code][/nobbc] tags.

From your mention of pin 53, sounds like you are running this on a Mega?

My code is:
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2 // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold. It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value. The default for a 16mhz AVR is a value of 6. For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
}

The library that it is referring to is the Arduino playground DHT11 library.
I am using a mega 2560.

The results that i get change when i blow on the sensor, so i know that it is working. When is use the built in pull up resistor i get the result:
Humidity: 1996.80 % Temperature: 588.80 *C 1091.84 *F Heat index: -3515596.50 *F
Humidity: 1971.20 % Temperature: 588.80 *C 1091.84 *F Heat index: -3395109.00 *F
Humidity: 1971.20 % Temperature: 588.80 *C 1091.84 *F Heat index: -3395109.00 *F
Humidity: 1945.60 % Temperature: 588.80 *C 1091.84 *F Heat index: -3276584.00 *F

So i don't think that it is the resistor.

Is there a way to alter the formula in the library to make it work?

I have had other sensors working so it is not a faulty Arduino (MQ 135 and LDR).

Pin2 = Connected to digital pin 53

#define DHTPIN 2     // what pin we're connected to
...
DHT dht(DHTPIN, DHTTYPE);

If you are using digital pin 53 on the Mega, I think you need to define DHTPIN as 53.

I tried that but I am still getting really high results like:
Humidity: 1996.80 % Temperature: 588.80 *C 1091.84 *F Heat index: -3515596.50 *F
Humidity: 1971.20 % Temperature: 588.80 *C 1091.84 *F Heat index: -3395109.00 *F
Humidity: 1971.20 % Temperature: 588.80 *C 1091.84 *F Heat index: -3395109.00 *F
Humidity: 1945.60 % Temperature: 588.80 *C 1091.84 *F Heat index: -3276584.00 *F

I know it's no the board of the pull resistor so it must either be the code or the sensor.
I presume that as the sensor changes when the temperature and humidity changes, that the sensor is not faulty.
So it must be the code, however the code seems to work for other people so I am at a loss.
The only possible solution that I could think of is to determine how far off the sensor is (100's C) and adjust the code to compensate for this however I don't have the skills to do that.
Are there any possible sources for the error?

Are you using a DHT11 or a DHT22 sensor? Your thread title says DHT11 but the code has DHT22 defined.

what is the the recommended DHT11 library?
from your code I assume you are using ADAfruits lib, which should work.

check this one - Arduino Playground - DHT11Lib - and see if it gives the same results.

Can you post a schema how things are connected?

It might be possible that your sensor is not a DHT11 but a DHT22, they have the same handshake but a different interpretation of the data. I should check the lib for the effect that would have but I expect the values would become smaller.

The Heat index uses the hum & temp so that is collateral damage.

@HS, you just beat me by a few minutes.

20C would be 020 000 for a DHT11
20C would be 000 200 for a DHT22

The formula for the DHT22 is (high*256 + low) / 10;

A DHT11 giving 20C would result in 20*256 / 10 = 512 C

in short there would be a factor 25.6 between interpretation of DHT22 and DHT11

HUMIDITY :1996.80 / 25.6 ==> 78 RH
TEMPERATURE: 588 / 25.6 ==> 23°C

so hackscribble caught the bug.

Thanks for your help everyone, so which line of code should I remove before uploading it to the Arduino again?
Is it the:
//#define DHTTYPE DHT11 // DHT 11
line?
As i still end up with results in the hundreds ...
I am using a DHT11, it also says DHT11 on the sensor.

I have just realised that I needed to remove the backslashes. The sensor now works :slight_smile: I would like to thank everybody for their help, I really appreciate it.