Raspberry Pi DHT 11 sensor not working. I get None None

Question:

Have integrated Raspberry pi4 with a DHT sensor.
The data pin is connected to pin GPIO 26

Have tried connecting the VCC to both 3.3V and 5V

Have tried with both Adafruit_DHT.DHT11 and Adafruit_DHT.DHT22 in the code for the same sensor but I get None None

import Adafruit_DHT

# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = Adafruit_DHT.DHT22
pin = 26

while True:
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    print(temperature, humidity)

Output:

None None

Is the sensor broken??Should I replace it or is there any other solution??

Asked By: Dev

||

Answers:

from pigpio_dht import DHT11, DHT22

gpio = 4 # BCM Numbering

sensor = DHT11(gpio)
#sensor = DHT22(gpio)

result = sensor.read()
print(result)

This worked for me. Before running the code enter the below commands on the terminal

sudo pigpiod #Start daemon

pigs pud 4 u # Set internal pull up

If pigpio-dht is not installed enter pip3 install pigpio-dht and run the above program

Answered By: Dev

After 3 days with the same issue and trying all of the above (even bought a new DHT11), the issue with just with the GPIO’s. I manually had to "push" the pin GPIO-4 to make it contact with the recevier end of the DHT11 cable.

my code was simpler version:

import Adafruit_DHT
import sys

while True:
 humidity, temperature = Adafruit_DHT.read_retry(11,4)
 print(temperature, humidity)
Answered By: user21031661