question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DHT22 Wrong temperature readings.

See original GitHub issue

The temperature output dropped to to 1°C when the real temperature got above 26°C.

Steps to reproduce

using var dht = new Dht22(26);
while (true)
 {
         // Try to read the temperature.
         var temp = dht.Temperature;
         if (!dht.IsLastReadSuccessful) continue;

          // Try to read the humidity.
          var humidity = dht.Humidity;
          if (!dht.IsLastReadSuccessful) continue;

          Console.WriteLine($"Temperature: {temp.Celsius:0.0} °C, 'Humidity: {humidity:0.0} %");

          break;
}

Expected behavior

Output: Temperature: 26.0 °C, 'Humidity: 36.1 %

Actual behavior

Output: Temperature: 1.0 °C, 'Humidity: 36.1 %

Versions used

Add following information:

  • Dotnet on the build machine: Version: 3.1.1 Commit: a1388f194c
  • Dotnet on the raspberry pi 3B: Version: 3.1.1 Commit: a1388f194c
  • Version of System.Device.Gpio package: 1.0.0
  • Version of Iot.Device.Bindings package: 1.0.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Ellerbachcommented, Mar 12, 2020

@fomenkodmitry and @BramEsendam, you are right, there was a mistake. I found some time to dig into the code and found the problem. Line 32 in the Dht222.cs file should be:

var temp = ((readBuff[2] & 0x7F) * 256 + readBuff[3]) * 0.1;

@joperezr, will make a PR asap.

0reactions
joperezrcommented, Mar 12, 2020

I’ve merged that PR so hopefully the results will be fine now. I’ll go ahead and close this issue assuming it does, but please feel free to reopen if that is not the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DHT22 Shows wrong values... how do I address this?
The temp in my room at the moment is about 22 degrees according to an LN35 I have wired up on another board....
Read more >
DHT22 sensors reporting bad values in ESPHome
I have just recently had to make a new sensor to subtract 2.3 from humidity and 1.6 from Temperature. to have this sensor...
Read more >
DHT22 wrong readings
I am experiencing wrong temperature and humidity readings when using a D1 mini (ESP8266) to read a DHT22 sensor. Temperature is 2 to...
Read more >
DHT22 inaccurate readings - adafruit industries
The datasheet says the relative humidity measurement is accurate to +/-2% on average, with a maximum error of +/-5%. For two sensors, those ......
Read more >
DHT22 incorrect temperature readings : r/arduino
I have a few problems with the sensor readings. Testing it on a room, at around 23ºC, gives 25ºC. The reference temperature I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found