How to Connect DHT11/DHT22 Temperature Sensor to ESP32

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
here's how to quickly connect up a dht11 or dht22 temperature and humidity sensor to an ESP 32 first of all I recommend buying the dht22 over the dht11 they're said to be more accurate and also more robust this cheap dht11 I bought from AliExpress no longer works here's a chart that compares the two types A dht22 is roughly twice the cost of a dht11 be sure to buy decent components that have good reviews now let's get the sensor connected to the esp32 and take some temperature and humidity readings most DHT sensors have three pins however you might encounter ones that have four pins if you have one that has three pins then the Plus One will go to the voltage so on the esp32 you can either connect that to the 3.3 or the 5V pin I recommend that you use 5 volts with the sensor if you're using 3.3 volts then you might find the device doesn't work so well if you're going to be using the sensor a long way away from the esp32 then you definitely want to use the 5V pin so apparently if you power up the sensor using 5 volts then you can place it up to 20 M away from the esp32 so if you got a three pin sensor then the data line is usually the one in the middle and you need to connect this to a digital pin on the esp32 I recommend using digital pin 2 I.E GP io2 to so now in the Udo IDE let's install the library so we can start using the sensor so you need to go to tools and then manage libraries then search for DHT sensor library and the one we want is the DHT sensor Library by Adafruit so if it's not installed then install it once you've installed it you can go to file and then examples okay so they are under examples from Custom libraries and then DHT sensor library and you want to use the DHT tester so this sketch is pretty much ready to go so first go to tools and then board manager and ensure You' got the ESP 32 selected so if you got a basic esp32 like mine then the one to select is the esp32 dev module this normally works with a lot of them you might be able to find yours here though if it's different just be very careful if you got the latest libraries because the esp32 S2 C3 and S3 are often listed at the top so make sure you have the right one selected you should also check that the esp32 is on the correct Port so on the comp Port mine is connected to com 5 so there are a couple of changes you might need to make depending on your circumstances earlier in the video I recommend connecting it to GP io2 so if you've connected it to do a different pin on the esp32 then you'll need to change this number if you're using a dht11 then you'll have to uncomment this line and comment out the dht22 line so I'm using a dht22 so I will uncomment that one if you don't know which one you got then generally generally generally speaking the DHT 11 is blue and the dht22 is white so scrolling down to the code there's not really much we have to do all you have to do is to in the setup routine is call DHT do begin and then in the loop it will take temperature readings so as I mentioned in the introduction the dht22 is much slower at taking readings so here we delay for two seconds between making readings if you're using ad dht11 then potentially you can take readings every 1 second so now I've connected up the sensor to the esp32 and the esp32 is connected to the PC so let's upload this sketch and get some temperature readings so hold down the boot Button while it's uploading the sketch and this is a problem I seem to be having if I've connected the dht22 to the esp32 it won't upload the sketch so the solution seems to be to disconnect the data feed from the esp32 while it's uploading a sketch so I'll try uploading again I don't know if it's just me that's having this issue or maybe because I'm not using a resistor or something but it is very strange so now it's uploading this sketch properly okay so now you can go to tools and then serial Monitor and change it to 9,600 if it's not on there already so there you see we are getting temperature readings so according to this it's 28° here let's see so I do have some other thermometers so this is a cheap little one that I bought for Muji so it has temperature and humidity okay so the DHT 22's humidity is exactly the same as this one the temperature seems way off so either this one is not very accurate this one might actually have a dht11 in it I haven't assembled it but you probably have a similar sensor to that this is my ancient radio controlled alarm clock and it's really accurate for time I'm not sure about temperature but it's years old so again it's quite similar to the Muji little device that I just showed the dht22 is definitely overstating things a it okay here's a very old analog sensor from the old days so this only records temperature so I think this one's recording about 24 and a half so for all the progress made with digital I would say that the analog one still wins is still very accurate it's been accurate for over 40 years now so if you want to do something with the data then the variable H has the humidity value in it the variable T has the temperature in Celsius or Centigrade finally the temperature in Fahrenheit is the F variable if you want to send this data to a PC or other computer or even to the cloud then I highly recommend using the mqtt protocol I've made a video about this so check this one out so that's basically all you need to do to hook up the esp32 to the dht11 or dht22 temperature sensor I hope you found this video useful thanks for watching
Info
Channel: Coding With Brett
Views: 642
Rating: undefined out of 5
Keywords: esp32 beginner guide
Id: YJXICV1_Kw0
Channel Id: undefined
Length: 6min 43sec (403 seconds)
Published: Sun Apr 14 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.