DHT22 temperature and humidity sensor not working with Raspberry Pi 5

August 14, 2024, 19:26

vaaazqueez

Good evening, I am starting in the world of the raspberry pi, and after having made small labs with leds, I want to get the temperature and humidity of my room. For this, I have bought in Alliexpress DHT22 sensor. I have seen and tried many tutorials, but I can't get any values. I always get the error: DHT sensor not found, check wiring. I am using a raspberry pi 5, and the python library adafruit_dht, as I have seen that some others do not work for the rb pi 5. As I said, I have tried several codes and none of them work. For example this one from https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup does not work for me (I can't attach the code because it is too long). The wiring I think is ok, I attach images. The resistor is 10K and I have also tested the 3.3V and 5V voltages offered by the board, and different GPIOs. Do you know what I could be doing wrong, maybe the sensor is defective? I hope you can help me! Thank you very much!



thunder07337

If the code is too long for the chat, use https://pastebin.com/

oops.se

The wiring look like it's wrong but it's hard to see as the red (positive) isn't connected to the DHT22 and the black (negative) is connected to pin 2 and that's supposed to be the GPIO pin. And the rotation of the parts bag is wrong. So describe your wiring.

vaaazqueez

Good morning, thank you for your reply. OK, I'll try to explain things a bit more clearly. The code used is the following: https://pastebin.com/LBLbGmaK . As for the schematic, I have changed the wires to make it clearer. I attach the pictures again. I also attach the photo of the bag where the sensor came in. Thank you very much for the help, I hope I can solve it as I am unable to get it even trying in many different ways.






thunder07337

If you're using a Raspberry Pi with a DHT22 (or an AM2302) sensor connected to Pin 4, change the following line from: dhtDevice = adafruit_dht.DHT22(board.D18) to dhtDevice = adafruit_dht.DHT22(board.D4)

vaaazqueez

But I´m using the GPIO18

vaaazqueez

Or i´m wrong?

thunder07337

Yes, because they use an adafruit board and it's 18. That's why the instructions say that if you use a Pi you have to change it!

thunder07337


vaaazqueez

So I change the code from board.D18 to board.D4 but I Iet the wiring on the GPIO18 asi it`s shown on my picture?

vaaazqueez

.

thunder07337

No, you have to connect it to GPIO 4.

thunder07337

And red to 3.3 V not to 5V

thunder07337


oops.se

And have a look at this tutorial, it will also give you an insight in "virtual environments" https://pimylifeup.com/raspberry-pi-humidity-sensor-dht22/

vaaazqueez

Hello again, I have set the volate to 3,3 and I have put in the GPIO4 (and consequently in the board.D4 code). It still doesn't work, I get the same error: DHT sensor not found, check wiring. I have read the article, and I do exactly the same. Do you know if there is any way to know if the sensor is failing (I don't have any other board where I can test it). What a desperation! hahahahahaha

vaaazqueez

Should I buy another sensor? Do you recommend a reliable website?