Reading Negative Temperatures with DHT22

I am using an Arduino MKR WiFi 1010 with an attached DHT22/AM2302 to measure outdoor temperature and humidity. The problem is that it does not report negative temperatures correctly. The temperature will either be a number below -3000 or it will stop at 0 C and not go lower. This problem has been reported numerous times in these forums and I have read all of them I can find, but nowhere is a real solution posted. There are numerous answers about significant bits, etc., but these don't help me. I have been coding for a long time, but am fairly new to the Arduino.

I have written the simplest sketch I can think of to demonstrate the problem. Could someone please post the exact line(s) of Arduino code that can read negative numbers.
Thank you.

// Temperature and Humidity Sensor
#include <DHT.h>
#define DHTTYPE DHT22
#define DHTPIN  1
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);

  // Initialize the temperature sensor.
  dht.begin();
}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  Serial.print(temperature);
  Serial.print("  ");
  Serial.println(humidity);
  delay(10000);
}

Please provide a link to the exact library that you are using.

It would be helpful to provide links to the discussions that you mentioned so we don't have to go hunting for them.

Libraries I am using for this example:
Adafruit DHT Sensor Library
Adafruit Unified Sensor Library

Some of the posts discussing this topic:
https://forum.arduino.cc/t/not-getting-negative-temperature-readings/664195
https://forum.arduino.cc/t/dht22-negative-temperature/695993
https://forum.arduino.cc/t/my-dht11-data-reading-value-temperature-humidity-got-negatif-and-ac-temp-zero-in-oled/932992

Did you run the library example sketches? Edit - this problem has been opened several times as "issues" on the Github page.
https://github.com/adafruit/DHT-sensor-library

Do you have the most recent version of the library?

Ran example problem "DHTtester". Same problem. All libraries are lastest.

There is already a pull request open for that bug.

Problem solved! The "DHT_Unified_Sensor" example you pointed me to in Github reads negative temperatures. I have my Arduino with DHT22 in my freezer with a cable running out to a Raspberry Pi running the Arduino IDE. The monitor is showing -20C and 60% RH.

Thanks for your help. Now I need to adapt the code from the example to my sketch and I should be in business.

1 Like

In case this could help someone else who may have had this problem, I am posting the modified "simple example" that will report negative temperatures accurately with a DHT22 sensor and Arduino board.

// Temperature and Humidity Sensor
// Uses 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 <Adafruit_Sensor.h>
#include <DHT_U.h>

#define DHTPIN 1
#define DHTTYPE    DHT22     // DHT 22 (AM2302)
DHT_Unified dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);

  // Initialize the temperature sensor.
  dht.begin();
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
}

void loop() {
  //Read the sensor event
  sensors_event_t event;
  
  //Get temperature & print value
  dht.temperature().getEvent(&event);
  float temperature = event.temperature;  
  Serial.print(temperature);
  Serial.print("  ");
  
  //Get relative humidity and print value
  dht.humidity().getEvent(&event);
  float humidity = event.relative_humidity;
  Serial.println(humidity);
  
  delay(10000);
}
1 Like

I take back what I wrote above. Based on additional testing that I have done, the problem of the DHT22/AM2302 not being able to report negative temperatures appears to be related to the brand of sensor used and not the code in the sketch. "Asair" brand sensors that I bought from Adafruit/Digi-Key report temperatures below 0C correctly using either of the sketches above. I bought several AM2302 sensors from Amazon with the brand name "Sensor" (really). They are marked on the back having a range of -40C to +80C. These sensors report temperatures around -3000C when the temperature goes below zero. Interestingly, the AM2302 contains a unit that looks exactly like a DHT22. There is also an almost identical DHT11 sensor on the market that is not designed to be used below 0C. Curious.

Plenty of counterfeit, reject and outright inoperative fake modules can be found on Amazon, FleaBay, Alibaba and the like.

You should not assume that a cheap sensor is even closely related to the real thing.

Yes, true. But you should explore the idea of mistaken identity if you want to recoup your investment. Try selecting different devices, when I played with DHT, there was a line in the header file to select the DHT type. Just try all of them, one at a time.

Please see my post from today about the same subject. The solution I found was switching to the DHTStable library. I had the same problem but with all ASAIR AM2302. Two of Five of the ones I had produced bizarre numbers at low temperatures. Primarily humidity, but also some temperature values in the 3000's. The problem was solved by using this library and switching the code to match.

If you want people to reference your posts, you have to link to them. Nobody is going to go hunting around the forum and trying to figure out when "today" was, 6 months from now.

I found the library with examples at https://github.com/RobTillaart/DHTstable
I will give it a try in the next few days.
Thank you for the suggestion.

So I tried Rob Tillaart's DHTstable example. I loaded his example on my MKR WiFi 1010 with the "Sensor" brand AM2302 and put both in the freezer. Interestingly, the relative humidity readings seemed to remain correct at temperatures below 0C, but the temperature readings again went to ~-3000 C.

Here are a few lines of the output:

DHT22, OK, 27.1, 0.1, 4495
DHT22, OK, 27.2, 0.0, 4341
DHT22, OK, 27.3, 0.0, 4374
DHT22, OK, 27.4, -3276.7, 4957
DHT22, OK, 27.5, -3276.7, 4992
DHT22, OK, 27.6, -3276.6, 4930
DHT22, OK, 27.7, -3276.5, 4956

I remain convinced that an unscrupulous vendor is using a DHT11 inside a shell and labeling it AM2302.

Sure, but did you try all the different sensor type configuration choices in the driver?

No, I did not. I don't see the logic. The DHT11 is not designed to read temperatures below 0C. I don't know why I would try type DHT11 for a sensor that is sold as a DHT22. I could try endless combinations, but what is the point? Since the "Asair" sensors work properly, my plan is to just use those.

The point is to find a configuration that matches the actual part, even if it's mislabelled. Endless? How many choices are there? I thought there were only 3 - DHT11, DHT12 and AM2302. But I agree, if you found the right ones, then there is no point.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.