Python Forum

Full Version: Wiring DHT11 to Raspberry pi
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm struggling with this simple setup with DHT11. I have wired in the 3-wire DHT11 sensor like this on my RP 2 model B version 1:
Vcc > pin 2 (5V)
Gnd > pin 9 (GND)
Data > pin 7 (GPIO 4)
and I keep getting "DHT sensor not found, check wiring"
I couldn't find a symbol for the 3-wire sensor so disregard the 4th pin.
I have installed the Adafruit_CircuitPython_DHT library.

    # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
    # SPDX-License-Identifier: MIT
     
    import time
    import board
    import adafruit_dht
     
    dhtDevice = adafruit_dht.DHT22(board.D4)
     
    while True:
        try:
            temperature_c = dhtDevice.temperature
            temperature_f = temperature_c * (9 / 5) + 32
            humidity = dhtDevice.humidity
            print(
                "Temp: {:.1f} F / {:.1f} C    Humidity: {}% ".format(
                    temperature_f, temperature_c, humidity
                )
            )

        except RuntimeError as error:
            # Errors happen fairly often, DHT's are hard to read, just keep going
            print(error.args[0])
            time.sleep(2.0)
            continue
        except Exception as error:
            dhtDevice.exit()
            raise error

        time.sleep(2.0)
Error:
DHT sensor not found, check wiring
[Image: DHT11.png]

I ran a debug on the code.

Output:
adafruit_dht <module 'adafruit_dht' from 'home/pi/.local/lib/python3.7/site-packages/adafruit_dht board <module 'board' from '/usr/local/lib/python3.7/dist-packages/board.py'> dhtDevice <adafruit_dht.DHT11 object at <0x757727b0> time <module 'time' (bulit-in)>
The '<0x757727b0>' looks like some kind of address. Could it be something to check? It looks like it has found the sensor after all so why doesn't it work?
And have you checked the wiring already? Smile
using the pinout diagram here: https://pi4j.com/1.2/pins/model-2b-rev1.html
diagram shows pin7 as GPIO 7, not GPIO 4
(Feb-05-2021, 11:07 PM)Larz60+ Wrote: [ -> ]using the pinout diagram here: https://pi4j.com/1.2/pins/model-2b-rev1.html
diagram shows pin7 as GPIO 7, not GPIO 4

It's difficult to know what information you can trust. I used the pinout from https://pinout.xyz/# and it differs from the one you mentioned. I changed the IO number now to 4 but it's the same. I also tried running the DHT11 off 5V and 3.3 but it makes no difference.