DHT22 (AM2302) slow reponse to temperature changes

Hi,

I tested a DHT22 sensor by putting it in a freezer from room temperature. When I first started, the temperature was around 20°C. After putting it in the freezer, it took about 8 mins for the temperature reading to reduce to -3°C. The sensor reading was updated every 2 seconds and it was reducing by 0.1-0.2°C every 2 seconds. Once removed from the freezer, it took another 10 mins to reach room temperature. Is it the nature of DHT22 or my code? I used Adafruit's installed library in Arduino.

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

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors
// - Adafruit Unified Sensor Lib: GitHub - adafruit/Adafruit_Sensor: Common sensor library

#include "DHT.h"

#define DHTPIN 2
#define DHTPIN2 4 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!
//define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#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.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);

void setup() {

Serial.begin(9600);
Serial.println(F("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 (the default)
float t = dht.readTemperature();

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

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print("\t");
Serial.print(h2);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print("\t");
Serial.print(t2);
Serial.println(F("°C "));

}

I think I have a DHT22 or DHT11 somewhere, but I don't recall using them. They have enough mass that it wouldn't surprise me to learn that they're slow to react though.

As to your code being the culprit, it doesn't compile, so it's impossible to say.

My experience is that they have quite a long lag. There's quite a mass there.

Please remember to use code tags when posting code

wildbill:
I think I have a DHT22 or DHT11 somewhere, but I don't recall using them. They have enough mass that it wouldn't surprise me to learn that they're slow to react though.

As to your code being the culprit, it doesn't compile, so it's impossible to say.

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

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

#include "DHT.h"

#define DHTPIN 2 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!
//define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#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.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {

  Serial.begin(9600);
  Serial.println(F("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 (the default)
  float t = dht.readTemperature();



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

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.println(F("°C "));

}

There was an error in the previous code, here's the corrected version. The library I used.

Thank you.

I don't see any issue with your code.

Based on Awol's experience with them, it looks like the sensor is slow to react. For a weather station or similar use, I can't see that that really matters. I'd be inclined to try another DHT22 to see if that one is especially slow, but I doubt it.

Does reaction time matter for your application?

The sensor I bought from mouser - Mouser DHT22

Do you think it's covered too much?

Yeah reaction time is crucial as I'm controlling a Peltier cooler and a humidifier to maintain the temperature and humidity level in a container based on the DHT22 data.

Try it. Your test with a sudden huge swing in temperature doesn't seem to be relevant unless the container you're trying to keep equilibrium in is suddenly thrust into a freezer. It may well be able to do a good enough job where there is slower change. If not, you'll obviously need something more sophisticated but I wouldn't give up on what you have based on the results of your initial testing.