GregH2O
Posts: 5
Joined: Sat May 23, 2020 2:11 pm

DHT22 and Raspberry Pi 4 b

Sat May 23, 2020 2:22 pm

Hi,

First time post, first time Pi user. I want to connect up a DHT22 to my new Pi 4 B. I am a complete novice.

I saw a page https://pimylifeup.com/raspberry-pi-hum ... sor-dht22/, that talks about it, but my DHT22 has three pins not four, so I initially connected it up with no breadboard, just the Pi. I then ran some Python on the Pi but just get back "none", "none" as responses.

import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 7

hum, temp = Adafruit_DHT.read_retry(DHT_SENSOR,DHT_PIN)
print ("Humidity is", hum)
print ("Temperature is", temp)


So I then connected it all up to a breadboard, and put a 10k ohm resister between DAT and VCC.

I still don't get anything back other than "none".

I don't think my code is wrong, but have a connected something wrong? I have some photos here.
Image
Image
Image

Also, generally questions, but should I be turning the Pi off everytime I connect/disconnect something, or is that being too cautious?

GregH2O
Posts: 5
Joined: Sat May 23, 2020 2:11 pm

Re: DHT22 and Raspberry Pi 4 b

Sat May 23, 2020 3:12 pm

Found the problem. I was using the pin number on the board, not the number of the GPIO pin (so I used 7, and should have used 4!).

pcmanbob
Posts: 9033
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DHT22 and Raspberry Pi 4 b

Sat May 23, 2020 3:19 pm

Hi.

So looking at your DHT22 board it already had a pull up resistor on the board , so you should only need to connect the following.

VCC to 3.3v pin
GND to ground pin
DAT to the data pin as per the software gpio 4 or physical pin 7

if it still does not work check you don't have the 1-wire interface enabled, run sudo raspi-config interfaces and make sure disabled is selected for 1-wire interface.

As for connecting things to the pi , its advisable to do all connections/disconnections with the pi powered off, and to check you have things connected correctly at least twice before powering pi.

Edit ....... problem solved while I was posting but will leave this up anyway.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

GregH2O
Posts: 5
Joined: Sat May 23, 2020 2:11 pm

Re: DHT22 and Raspberry Pi 4 b

Sat May 23, 2020 3:26 pm

Hi pcmanbob,

Thanks for the response.
So looking at your DHT22 board it already had a pull up resistor on the board

So I don't need the breadboard?


EDIT: Nope, tried it without, and all good :)

Return to “Automation, sensing and robotics”