DHT 22 (Raspberry Pi)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's video i'm going to be showing you how to set up the dht22 temperature and humidity sensor with the raspberry pi so as always i just want to let everyone know that you can find the official write-up as well as all the components in the description below so let's quickly discuss the components that you're going to need in this case i'm using a raspberry pi 4 and a dht22 slash breakout board with the provided jumper cables just a quick note about the dht22 you can find the sensor in raw form online but this tutorial we're going to use the breakout board which comes provided with a 10k resistor and that's important because if you were to wire the raw sensor to the pi you have the potential to burn up the pin and you know get a regular behavior so let's proceed with the physical setup the first thing you need to do is wire the female dupont jumper cables to the dht sensor breakout in this case i've wired the yellow cable to positive the orange to out and the red to negative and then on the raspberry pi side i've wired the yellow cable to 3.3 volts the orange to gpio4 and the red to ground i'll throw up a schematic here so that you can see it more clearly so that completes the physical setup so now we're ready to boot up the pi open up a terminal and set up the os and then proceed with configuring the python script okay so i ssh into my raspberry pi if you're using the gui you can just open up a terminal and follow along it's the exact same process so the first thing that we need to do is install the dht library so the command that you're going to run is pseudo pip 3 install adafruit dash circuit python dht and hit enter okay so let's clean up the screen a bit so you want to open up a browser now and navigate to the dht i get web page i'll leave a link in the description and then you'll find that there's this examples subfolder and if we open it we have two uh test files so we're gonna inspect the simple test and basically this is the code that we need to run uh on the raspberry pi so we're just gonna copy everything here okay so on our raspberry pi i'm just going to create a script file real quick so type sudo nano ht test dot py copy the contents control x y enter sudo nano dht so i'm gonna walk you through kind of how the code works and we do have to make a few changes here so the first three lines we're just importing um you know the library and then on line six we are specifying the gpio interface but this is actually wrong we're going to need to comment out this line because this is for circuit python i believe we're going to have to uncomment line number 11 and change the d18 to 4 so basically that we're just specifying the gpo pin that we've set and then on line 13 through 20 we're looping through and reading the raw values on the sensor and making the necessary conversions there's some error checking that's going on on this block here 25 through 30 and that's pretty much how it works every two seconds it will pull the sensor and post the value so let's uh save this and see if it works so we're going to type sudo python3 ht test.ui so as you can see it's actually posting the values and don't be alarmed if you see this checksum did not validate error the sensor is actually very difficult to read so if the checksum fails uh you won't get the value so one easy way to get rid of that if you don't want to see it um is to go back to the script and then you can just comment out that line here now you should just only get the values and yeah so that concludes the tutorial for today to set up the dht22 sensor with the raspberry pi as always it's always appreciated if you leave a like and subscribe happy hacking peace
Info
Channel: PiddlerInTheRoot
Views: 20,006
Rating: undefined out of 5
Keywords: Raspberry, Pi
Id: EcyuKni3ZTo
Channel Id: undefined
Length: 5min 16sec (316 seconds)
Published: Wed Jan 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.