photo of wiring 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)


None None

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

Thanks in Advance


  • Does your DHT11 contain a 10K pull up resistor? Post a photo of your wiring.
    – CoderMike
    Mar 5 at 12:55
  • @CoderMike Have posted a photo please check it out Mar 5 at 13:10
  • Do not connect the DHT11 to 5V on a Raspberry Pi. Since most of these boards contain a pull-up resistor, this might damage the GPIO pins.
    – PMF
    Mar 6 at 7:29
  • @PMF ok..but i still don't get required output Mar 7 at 12:03
  • It is normal that these senors sometimes require multiple attempts to deliver a correct result, but that it never works is quite unusual. Mine work fine with a very similar setup.
    – PMF
    Mar 7 at 14:28

Here is some working code.

pigpio DHT example.

It needs the pigpio daemon to be running.

sudo pigpiod

Then assuming the script file is called DHT.py run with

./DHT.py 26 # if connected to GPIO 26


./DHT.py 7 # if connected to pin 26

See https://pinout.xyz/ for the mapping between pin and GPIO numbers.

If it doesn't work either the wiring or the sensor is faulty.

  • if run sudo pigpiod i get " 2021-03-05 18:46:15 initInitialise: Can't lock /var/run/pigpio.pid Can't initialise pigpio library" if i run ./DHT.py 26 i get " ./dht2.py: line 1: import: command not found ./dht2.py: line 5: sensor: command not found ./dht2.py: line 13: pin: command not found" Its a python file why run as a shell script? I have uploaded the photo of wiring, please check it out Mar 5 at 13:18
  • Is the pigpio daemon running? Does pigs t return a number? Use python DHT.py 26 if you prefer. The wiring seems okay.
    – joan
    Mar 5 at 13:27
  • If I give command "sudo pigs t" I get "381125293" If I run sudo "python3 dht2.py 26" I get "None None" Mar 5 at 15:55
  • Please run the script I provided. It MUST be called DHT.py (not dht.py, not x.py, not dht2.py).
    – joan
    Mar 5 at 16:08
  • For the command python DHT.py 26 I get: 1614974667.288 26 3 0.0 0.0 1614974669.559 26 3 0.0 0.0 1614974671.828 26 3 0.0 0.0 1614974674.099 26 3 0.0 0.0 1614974676.371 26 3 0.0 0.0 1614974678.642 26 3 0.0 0.0 1614974680.913 26 3 0.0 0.0 Here 3 means no response from the sensor. could you please say should I replace the sensor or is there any other option? Mar 5 at 20:10
from pigpio_dht import DHT11, DHT22

gpio = 4 # BCM Numbering

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

result = sensor.read()

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.