1

I am currently working on a Raspberry Pi Pico W project where I need to use the DHT11 sensor to return humidity and temperature however the results are returning -1 for both the temperature and humidity.

I've included a picture of the circuit as well as the code. I would appreciate any help or tips on this!

image of circuit

from machine import Pin, I2C
import utime as time
from dht import DHT11

pin = Pin(13, Pin.OUT, Pin.PULL_DOWN)

sensor = DHT11(pin)

while True:
    print("Temperature: {}, Humidity: {}".format(sensor.temperature, sensor.humidity))
    time.sleep(1)

I've tried another sensor, rewiring the circuit, and different code variations I've seen online and I am still getting a -1 for both temperature and humidity.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • I don't use DHT11, but I can't help feeling `Pin.out` is going to be wrong for reading data. – Mark Setchell Mar 24 '23 at 07:47
  • 1
    @MarkSetchell Because communication with the DHT11 involves signalling in both directions, the initial configuration of the pin for input-vs-output doesn't matter; the underlying module takes care of switching between modes as necessary (and I think the module takes care of managing the pull up/down setting as well). – larsks Mar 24 '23 at 11:55
  • 1
    @larsks Thank you for taking the time to put me straight. – Mark Setchell Mar 24 '23 at 13:42

0 Answers0