-1

In the comment of an existing answer that says a resistor is required, a person said that Pi's pins have in-built resistors ( https://raspberrypi.stackexchange.com/a/12162/121818 ), but it was just a comment and did not give the full source code.

I combined the comment code and the code from this article. Is this the correct code for using a DHT22 without a resistor? It does print values, but I am not sure those are correct values. The temperature seem quite high.

DHT22's pin1 is connected to Pi's pin1, pin2 to pin7, pin4 to pin6.

import Adafruit_DHT
import RPi.GPIO as GPIO

sensor = Adafruit_DHT.DHT22
gpioNumber = 4
pinNumber = 7

GPIO.setmode(GPIO.BOARD)
GPIO.setup(pinNumber, GPIO.IN, pull_up_down = GPIO.PUD_UP)

hum, tem = Adafruit_DHT.read_retry(sensor, gpioNumber)
print("humidity = " + str(hum) + ", temperature = " + str(tem))
3
  • which resistor are you talking about?
    – jsotola
    Jul 18, 2020 at 20:39
  • What makes you think you (or some article) knows more about the DHT22 than the manufacturers? The vast bulk of us follow the data sheet.
    – Milliways
    Jul 18, 2020 at 22:14
  • NOTE The Adafruit code is clumsy and unreliable - it also requires root permission to run. See raspberrypi.stackexchange.com/a/105549/8697
    – Milliways
    Jul 19, 2020 at 0:43

1 Answer 1

1

The Pi's GPIO each have pull-up and pull-down resistors which may be switched into circuit via software.

These are quite weak (70k ohms or such). The internal pull-up resistor may be enough for the DHT to work reliably depending on connector length.

Normally a strongish 4k7 ohms resistor is added between the DHT data line and 3V3.

If you get reliable readings then whatever you are doing is okay. Only you can tell if the readings are reliable or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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