Arduino UNO DHT22 Humidity 99.9

Hello,

I'm facing problem reading the humidity from my DHT22 AM2302 with an Arduino Uno.

I tried different kind of example with different library and nothing seems to help me.
I can access the temperature but the humidity is always displaying 99.9

Oh and the first time I was monitoring it, the humidity was displaying properly but it started increasing up to 99.9 and it stayed there ever since...

Any pointers?

I made sure the voltage is not exceeding 5vdc.

Thanks
Phil

1k pullup (pin 2 to 5V) installed ?

I had a 4k7 and now i just tried a 1k and the same result.

I also tried a different input on the arduino and a jumper between gnd, pin 3 and 4 of the DHT22.

can you post the code?
do you use a library?
if so, which?

Just today I tried the one on the main page of DHT22 arduino.cc

And yes I use the following library .h and .cpp

Here is the example code I used;

//
//    FILE: dht_test.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
//     URL: http://arduino.cc/playground/Main/DHTLib
//
// Released to the public domain
//

#include <dht.h>

dht DHT;

#define DHT22_PIN 7

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
  // READ DATA
  Serial.print("DHT22, \t");
  int chk = DHT.read22(DHT22_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
		Serial.print("OK,\t"); 
		break;
    case DHTLIB_ERROR_CHECKSUM: 
		Serial.print("Checksum error,\t"); 
		break;
    case DHTLIB_ERROR_TIMEOUT: 
		Serial.print("Time out error,\t"); 
		break;
    default: 
		Serial.print("Unknown error,\t"); 
		break;
  }
  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.println(DHT.temperature, 1);

  delay(1000);


    // READ DATA
  Serial.print("DHT21, \t");
  chk = DHT.read21(DHT21_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
		Serial.print("OK,\t"); 
		break;
    case DHTLIB_ERROR_CHECKSUM: 
		Serial.print("Checksum error,\t"); 
		break;
    case DHTLIB_ERROR_TIMEOUT: 
		Serial.print("Time out error,\t"); 
		break;
    default: 
		Serial.print("Unknown error,\t"); 
		break;
  }
  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.println(DHT.temperature, 1);

  delay(1000);

  // READ DATA
  Serial.print("DHT11, \t");
  chk = DHT.read11(DHT11_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
		Serial.print("OK,\t"); 
		break;
    case DHTLIB_ERROR_CHECKSUM: 
		Serial.print("Checksum error,\t"); 
		break;
    case DHTLIB_ERROR_TIMEOUT: 
		Serial.print("Time out error,\t"); 
		break;
    default: 
		Serial.print("Unknown error,\t"); 
		break;
  }
 // DISPLAY DATA
  Serial.print(DHT.humidity,1);
  Serial.print(",\t");
  Serial.println(DHT.temperature,1);

  delay(1000);
}
//
// END OF FILE
//

dht.h

//
//    FILE: dht.h
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.09
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
//     URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// see dht.cpp file
//

#ifndef dht_h
#define dht_h

#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

#define DHT_LIB_VERSION "0.1.09"

#define DHTLIB_OK				0
#define DHTLIB_ERROR_CHECKSUM	-1
#define DHTLIB_ERROR_TIMEOUT	-2
#define DHTLIB_INVALID_VALUE	-999

class dht
{
public:
    int read11(uint8_t pin);
    int read21(uint8_t pin);
    int read22(uint8_t pin);

    double humidity;
    double temperature;

private:
    uint8_t bits[5];  // buffer to receive data
    int read(uint8_t pin);
};
#endif
//
// END OF FILE
//

dht.ccp

//
//    FILE: dht.cpp
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.08
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
//     URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// 0.1.09 optimize size: timeout check + use of mask
// 0.1.08 added formula for timeout based upon clockspeed
// 0.1.07 added support for DHT21
// 0.1.06 minimize footprint (2012-12-27)
// 0.1.05 fixed negative temperature bug (thanks to Roseman)
// 0.1.04 improved readability of code using DHTLIB_OK in code
// 0.1.03 added error values for temp and humidity when read failed
// 0.1.02 added error codes
// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011)
// 0.1.0 by Rob Tillaart (01/04/2011)
//
// inspired by DHT11 library
//
// Released to the public domain
//

#include "dht.h"

// #define TIMEOUT 10000
// uint16_t for UNO, higher CPU speeds => exceed MAXINT.
// works for DUE
// 16 MHz => 10000
// 84 MHz => 52500
// 100MHz => 62500
#define TIMEOUT (F_CPU/1600)


/////////////////////////////////////////////////////
//
// PUBLIC
//

// return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht::read11(uint8_t pin)
{
    // READ VALUES
    int rv = read(pin);
    if (rv != DHTLIB_OK)
    {
        humidity    = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
        temperature = DHTLIB_INVALID_VALUE; // invalid value
        return rv;
    }

    // CONVERT AND STORE
    humidity    = bits[0];  // bits[1] == 0;
    temperature = bits[2];  // bits[3] == 0;

    // TEST CHECKSUM
    // bits[1] && bits[3] both 0
    uint8_t sum = bits[0] + bits[2];
    if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;

    return DHTLIB_OK;
}

// return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht::read21(uint8_t pin)
{
    return read22(pin);  // dataformat identical to DHT22
}

// return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht::read22(uint8_t pin)
{
    // READ VALUES
    int rv = read(pin);
    if (rv != DHTLIB_OK)
    {
        humidity    = DHTLIB_INVALID_VALUE;  // invalid value, or is NaN prefered?
        temperature = DHTLIB_INVALID_VALUE;  // invalid value
        return rv; // propagate error value
    }

    // CONVERT AND STORE
    humidity = word(bits[0], bits[1]) * 0.1;

    if (bits[2] & 0x80) // negative temperature
    {
        temperature = -0.1 * word(bits[2] & 0x7F, bits[3]);
    }
    else
    {
        temperature = 0.1 * word(bits[2], bits[3]);
    }

    // TEST CHECKSUM
    uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
    if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;

    return DHTLIB_OK;
}

/////////////////////////////////////////////////////
//
// PRIVATE
//

// return values:
// DHTLIB_OK
// DHTLIB_ERROR_TIMEOUT
int dht::read(uint8_t pin)
{
    // INIT BUFFERVAR TO RECEIVE DATA
    uint8_t mask = 128;
    uint8_t idx = 0;

    // EMPTY BUFFER
    for (uint8_t i=0; i< 5; i++) bits[i] = 0;

    // REQUEST SAMPLE
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
    delay(20);
    digitalWrite(pin, HIGH);
    delayMicroseconds(40);
    pinMode(pin, INPUT);

    // GET ACKNOWLEDGE or TIMEOUT
    unsigned int loopCnt = TIMEOUT;
    while(digitalRead(pin) == LOW)
    if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;

    loopCnt = TIMEOUT;
    while(digitalRead(pin) == HIGH)
    if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;

    // READ THE OUTPUT - 40 BITS => 5 BYTES
    for (uint8_t i=0; i<40; i++)
    {
        loopCnt = TIMEOUT;
        while(digitalRead(pin) == LOW)
        if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;

        unsigned long t = micros();

        loopCnt = TIMEOUT;
        while(digitalRead(pin) == HIGH)
        if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;

        if ((micros() - t) > 40) bits[idx] |= mask;
        mask >>= 1;
        if (mask == 0)   // next byte?
        {
            mask = 128;
            idx++;
        }
    }

    return DHTLIB_OK;
}
//
// END OF FILE
//

connect NOTHING to pin 3.
Your code is the example code.. unchanges except data_pin

Exactly it is the sample code.

Yes i tried to ground pin 3 because nothing else worked.

I guess U read temp correct..
As a last way out:
Try the other libraries mentioned on this page.. (a bit down on page)
http://playground.arduino.cc/Main/DHTLib
If thet all return temp OK and RH far out... Replace sensor

Today I changed the DHT22 with a new one and it works.

So I guess the humidity sensor in it was bad. Is it a common occurrence with those?

Thanks
Phil

Humidity sensors can easily be affected by the wrong gasses or very long exposure to high humidity IIRC.
In the datasheet there is a procedure how to "reset" the sensor, you could give it a try.

Mine got stuck on 99.9%. I tried a lot of stuff. And give up. Then I thought of washing it with methylated spirits and it worked.

I think you put power > 5.2V

From what I remember they are not designed to handle 100% RH or any contact with liquid
water (indoor use only, basically).

Before I get to much further I know others will be looking for help on the same Issue. Before using my solution please work through this tutorial first to eliminate the obvious stuff first.

If you find you have correct temperature but you still have the 99.9% humidity please read on!!

I did some research on how the am2302 sensor sensor is constructed and how the sensor functionally operates.

There is a moisture holding membrane between two electrodes. As per the URL provided.

Should this layer become saturated you will get a readout of maximum resistivity, Hence the 99.90% read out.

So the solution is to "dry" the sensor out.

An example of how I did this was by submerging the sensor methylated spirits for a couple of hours and then left to dry ( dry heat works best, do not blow dry other wise you will end up right back where you started form the moisture in the air).

I also tried putting the sensor in an over night in a container with a moisture absorber (damprid) which also worked for a larger group of sensors.

If this solution worked for you please ADD some karma TIA :smiley:

Hi everyone,

Following from @Slant_Eng 's advice above, I did blow dry air from hair dryer directly to the sensor (5-10 cm away), as it was attached to my nodemcu (soldered), and it fixed it! :slight_smile: The dht22 was showing 99.90% humidity for over two weeks (worked fine before that and temperature is accurate) and I have already replaced one sensor for the same reason some months ago. I am now thinking that I should not have... hair dryer is a solution!

Thanks @Slant_Eng and all other related input on the matter!
Together we will prevail :o :slight_smile:

PS: unfortunately not fixed... See the data after heating up the sensor and letting it cool down below.
|t = 25.94C |h = 99.90%
|t = 62.41
C |h = 43.80%
|t = 52.10C |h = 45.70%
|t = 48.65
C |h = 50.60%
|t = 48.48C |h = 57.20%
|t = 44.52
C |h = 59.50%
|t = 42.63C |h = 67.30%
|t = 42.00
C |h = 74.20%
|t = 41.75C |h = 78.70%
|t = 41.15
C |h = 83.70%
|t = 40.95C |h = 96.20%
|t = 35.99
C |h = 99.90%