Python Forum
Wiring DHT11 to Raspberry pi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wiring DHT11 to Raspberry pi
#1
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?
Reply


Messages In This Thread
Wiring DHT11 to Raspberry pi - by hcccs - Feb-05-2021, 10:02 PM
RE: Wiring DHT11 to Raspberry pi - by Jeff900 - Feb-05-2021, 10:12 PM
RE: Wiring DHT11 to Raspberry pi - by Larz60+ - Feb-05-2021, 11:07 PM
RE: Wiring DHT11 to Raspberry pi - by hcccs - Feb-06-2021, 08:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  DHT11 output to website problem cjdock 0 2,035 Oct-01-2019, 08:29 PM
Last Post: cjdock
Question DHT11 Sensor Programming bmakloski 3 4,411 Jun-28-2018, 06:59 PM
Last Post: bmakloski
  Writing data from a DHT11 to LCD expplane 2 4,109 Aug-07-2017, 03:38 PM
Last Post: expplane

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020