adafruit/DHT-sensor-library

DHT11 wont read below 0 degree celsius

beicnet opened this issue · 2 comments

Hi there,

I'm using Arduino UNO and the new variant of the Asair DHT11 (not the Aosong) sensor over 3.3v.

image

Everything is working just fine until the sensor reading get to 0 degree celsius and it just wont go below.

Outside right now is -3c

btw. I'm using library version 1.3.0

Thank you for your support!

I have fixed this code in DHT.cpp.

My sensor also has the "feature" that it reports 0x0000 for 0°C as well as 0x8000 for 0°C.
Following the logic this is -327.7°C ...

 case DHT22:
    case DHT21:
      int16_t d = ((int16_t)data[2]) << 8 | data[3];
	  //	msb set == negativ
	  if (d & 0x8000) {
		  d &= 0x7fff;
		  //	0x8000 == 0x0000 == 0)
		  if ( d == 0 ) d = 0x7fff;
		  d = 0x7fff - d;
		  d *= -1;
	  }
	  f = d * 0.1f;

      if (S) {
        f = convertCtoF(f);
      }
      break;