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
#2
And have you checked the wiring already? Smile
Reply
#3
using the pinout diagram here: https://pi4j.com/1.2/pins/model-2b-rev1.html
diagram shows pin7 as GPIO 7, not GPIO 4
Jeff900 and bowlofred like this post
Reply
#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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  DHT11 output to website problem cjdock 0 1,458 Oct-01-2019, 08:29 PM
Last Post: cjdock
Question DHT11 Sensor Programming bmakloski 3 3,396 Jun-28-2018, 06:59 PM
Last Post: bmakloski
  Writing data from a DHT11 to LCD expplane 2 3,343 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