DTH22 stop read afeter few redings


for the first time I put together an Arduino Mega 2650 and a DTH22/AM2302 t&RH sensor. Put the pull up resistor at 4,7kOhm and loaded a couple of example codes. In both cases I get the following anomaly: - after an upload or a reset, the reading start okay, but after few (i.e 2 to 10, never the same figure) the reading of T&RH% stops and Arduino return endless error messages, until next reset.

I wonder why that.. any tips?

Many thanks!


Hi, I've done some more digging.. no success, but at least some more knowledge. I've got the feeling that the problem lie in the Arduino/code.

If I look to the data line I see the following: - under regular operation at each 2seconds the line goes low (asking for a reding if I well understood the protocol) and after some 20msec I see the data frame, lasting about 4msec. - when it stopo reading, the data line is always high, as the Arduino missed to pull it down

Any tips where to look further.. ?

Many thansk to all!


Please post your code, library used and schematics.

remember the DHT22 needs time between readings (1 or 2 seconds)

Here the code: it’s the example given b y Adafruits. Libraries are properly added and imported. No warning nor of course errors during compiling.
Schematis is very straigth: Vcc sensor to +5V, Gng sensor to GND, data sensor to Arduino pin 2, pull up at +5V with 4,7kOhm as request. Timing is 2sec delay between reading, accordingly the datasheet.

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN            2         // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
//#define DHTTYPE           DHT11     // DHT 11 
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
//#define DHTTYPE           DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview


uint32_t delayMS;

void setup() {
  // Initialize device.
  Serial.println("DHTxx Unified Sensor Example");
  // Print temperature sensor details.
  sensor_t sensor;
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" *C");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" *C");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" *C");  
  // Print humidity sensor details.
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println("%");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println("%");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println("%");  
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;

void loop() {
  // Delay between measurements.
  // Get temperature event and print its value.
  sensors_event_t event;  
  if (isnan(event.temperature)) {
    Serial.println("Error reading temperature!");
  else {
    Serial.print("Temperature: ");
    Serial.println(" *C");
  // Get humidity event and print its value.
  if (isnan(event.relative_humidity)) {
    Serial.println("Error reading humidity!");
  else {
    Serial.print("Humidity: ");

I have tried also the following code, also given as example on the web. The same problem… :frowning:

#include <DHT.h>

    #define DHTPIN 2     // what pin we're connected to
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
  //  #define fan 4
  //  int maxHum = 60;
  //  int maxTemp = 40;
    void setup() {
    //  pinMode(fan, OUTPUT);
    void loop() {
      // Wait a few seconds between measurements.
      // 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();
      // Check if any reads failed and exit early (to try again).
      if (isnan(h) || isnan(t)) {
        Serial.println("Failed to read from DHT sensor!");
     // if(h > maxHum || t > maxTemp) {
     //     digitalWrite(fan, HIGH);
     // } else {
     //    digitalWrite(fan, LOW); 
     // }
      Serial.print("Humidity: "); 
      Serial.print(" %\t");
      Serial.print("Temperature: "); 
      Serial.println(" *C ");

And below a tipical output, as seen in the serial monitor: after few reading it stops and gives error messages continuosly (not waiting 2sec. to retray)

Temperature Sensor: DHT22 Driver Ver: 1 Unique ID: -1 Max Value: 125.00 *C Min Value: -40.00 *C

Resolution: 0.10 *C

Humidity Sensor: DHT22 Driver Ver: 1 Unique ID: -1 Max Value: 100.00% Min Value: 0.00%

Resolution: 0.10%

Temperature: 26.60 *C Humidity: 50.50% Temperature: 26.60 *C Humidity: 50.90% Temperature: 26.60 *C Humidity: 50.90% Temperature: 26.60 *C Humidity: 51.00% Error reading temperature! Error reading humidity!

I never poll the DHT22 sensor faster than 2500mSec.
Why not try increasing your delay time to try ?

Also, I never use the Adafruit library, but rather the nice library as produced by Rob Tillaart.
Better DHT22 library


Hi Paul,

thanks for the tips. I'm not at home for few days, so I cannot check it immediately. I've already tried to poll the sensor on a longer base, 3-4-5 seconds, but no changes. After some readings it stops.. >:( Surely I',ll try the library you suggested me as well another kind of Arduino board. I'll keep you all up to date here about my findings.

Many thanks so far.


sorry, I don't know how to use the library you suggested to me :( . By the way, I've tried to raise up to 5 seconds the polling interval with the ones given by Adafruit, it fails anyway. Any more tips?

Hello,I've found this: http://forum.arduino.cc/index.php/topic,22528.0.html

I'm testing now, but after 20 minutes no reading was missed.. so, I'm optimist I found a fix.

Thanks to all!


Sorry Pierlugi, I missed your post. Well, it is good you have it working at least now.

If you look at Rob Tillaart's GitHub you will see example use for his library. DHT_22 Test

Rob does a fine job with this and other libraries and is always keeping them up to date. They have never failed me yet.