Reading Negative Temperatures with DHT22

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