I am logging Temp and Hum with the DHT22 sensor every minute. Every Now and than a wrong measurement occurs. So long I recorded 4days 7hours and and within this period 3, measurements with totally wrong readings occurred. Is this something I should get used to and maybe solve codewise or is there an answer to why those reading appear that seldom:

2016-04-06 11:39    19.0    49.0
2016-04-06 11:40    19.0    48.8
2016-04-06 11:41    6.2 36.1
2016-04-06 11:42    19.1    48.9
2016-04-06 11:43    19.1    48.8
  • You should code defensively, and expect things to go wrong. In this cased tossing outliers (values that differ from the previous record by some amount), or compute an average over some time inteval. Commented Apr 6, 2016 at 17:42
  • thanks that is what I am going to do I guess, the outliers thing, I was just wondering if this is a common problem since I've seen this sensor a lot in tutorials, and projects and can't remember this problem mentioned anywhere
    – Peter S
    Commented Apr 6, 2016 at 17:45
  • It can and does happen, most tutorials only describe the happy case. Commented Apr 6, 2016 at 17:46
  • Ok thanks so far... but why do both readings (temp and hum) are wrong? It never occurred that only Temp was wrong and Hum was Ok or the other way arround?
    – Peter S
    Commented Apr 6, 2016 at 18:09

1 Answer 1


The fault you refer to is in the software. It can't handle the timing required.

Try my http://abyz.me.uk/rpi/pigpio/examples.html#pdif2_DHTXXD

There seems to be an actual fault with the DHT22 - it stops responding after a random time. The only solution I know of is a restart - see my http://abyz.me.uk/rpi/pigpio/examples.html#Python_DHT22_py

  • Thx for the help. So when humidity, temperatur = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, '22') I could turn the pin off and on at the beginning of the Log Script to avoid wrong readings? I'm using cron to run the script every minute.
    – Peter S
    Commented Apr 6, 2016 at 18:59
  • Don't waste your time. The library does the work. It is software.
    – joan
    Commented Apr 6, 2016 at 19:23
  • I read my comment. It seemed insulting. All I can say is it that was not the intention.
    – joan
    Commented Apr 6, 2016 at 19:31
  • Ok? I really meant "thank you for the help" . It did not come to me as an insulting comment. I'm going to look into your DHTXXD.zip file to log my reading from now on. Thank you very much. I really appreciate your help
    – Peter S
    Commented Apr 6, 2016 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.