0

I am trying to use my Raspberry Pi Zero W for an IoT project. I want to read the temperature of a room. I have the DHT22 sensor (the blue 3 pin one that has the resistors soldered onto the pcb).

I have been using the example code and its "working," but the accuracy is way off. I have an arduino to compare it to and its accurate, so the sensor is fine (I'm literally just replacing it on the breadboard). Pinout wise, I have G connected to pin 39 (ground), V connected to pin 1 or 2 (3.3 or 5, theres not difference), and S to pin 11 (GPIO17)

import Adafruit_DHT
import time
import board

DHT_SENSOR = Adafruit_DHT.DHT22 DHT_PIN = 17

while True:

humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN) print("Temp is "+ str(temperature))

temp = temperature(9/5)+32 print("Temp oF is " + str(temp)) if humidity is not None and temperature is not None: print("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature,humidity)) else: print("Failed to retrieve data from humidity sensor")

The output looks like this. The value should be ~80 oF

output

Any idea what could be causing such a wild inaccurate reading? I tried searching for any similar topics, but seems like I'm the rare case where its working but off by a giant magnitude (compared to off by a little).

Any help would be appreciated! Thanks!

  • 1
    Frankly the Adafruit code is notoriously unreliable. The DHT22 requires precision timing, easy on a micro controller like Arduino, but extremely difficult on a multitasking OS. See https://raspberrypi.stackexchange.com/questions/105548/reliable-temperature-humidity-logging-with-python-and-a-dht11 – Milliways Aug 25 '22 at 01:43
  • @Milliways thats unfortunate. I tried running the code in the link but it appears the DHT module may no longer be existent? or I cant seem to download it? – zealotben Aug 25 '22 at 14:28
  • @Milliways I found the code. To include the module, do I just make sure its in the same directory as my main code? I'm a bit of a rookie with relative pathing – zealotben Aug 26 '22 at 02:35
  • Just follow the instructions "DHT.py download "module" from http://abyz.me.uk/rpi/pigpio/code/DHT.py" "Unless DHT.py is in the same directory it should be in a directory on the PYTHONPATH" – Milliways Aug 26 '22 at 02:42
  • @Milliways it works (albeit off by a couple degrees compared to the arduino)! thanks for all your help! Its interesting that there appears to be 3-5 DHT11 drivers. – zealotben Aug 31 '22 at 02:56

0 Answers0