ESP32 Tutorial - DHT11/DHT22 (Temperature and Humidity Sensor)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everyone in this new lesson we are going to take a look at how to use the DHT sensor that allows you to read the temperature and the humidity we are going to hook it up to the esp32 board then we'll use a library that is called the HD sensor Library and it allows you to get the temperature and the humidity using the sensor so without any further Ado let's dive right into it [Music] in this new video you will need the DHT sensor this is called dht11 but if you have another version like dht22 you could use it with the same way basically we have three pins that we need to hook up to the esp32 board one of them is labeled minus which goes to the gnd of the esp32 board this one is the VCC which goes to the 5 volt pin of the esp32 board or you could use 3.3 volts as you can see we have this pin on top that you could use because this sensor doesn't require a high voltage to Power It Up and the last pane is labeled s which is the signal pane you could hook it up to one of the gpio bands in this tutorial I will use the gpio pair number 26 but you could use any of the other digital pens I have the VCC on the right side the gnd on the left side and the data or the signal is the middle pane then we can move on to the Arduino IDE and use the DHD sensor Library basically we are going to display the values on the serial monitor but later on we are going to create a DHT server that allows you to read the temperature and the humidity from your smartphone using the Wi-Fi capability let's go to the library manager and search for the HD sensor Library and here it is it is called the HD sensor Library I'm using the version 1.4.4 make sure to hit the install button once you do that we can start off by including this Library using hash then include and the name DHT after that we can create a DHT object the type is DHT that comes with this Library then we can give it a name like the HD lowercase and in these parentheses we add two parameters the first one is the pin that we have used it in my case I've used the GPA open number 26. then the type of D sensor because we have two versions ddhd11 and the dht22 sensor make sure to write the same type that you have after that we have to initialize it under the setup function using DHT which is the name of the object dot begin it is recommended to add a bit of delay like 2 seconds because this kind of sensors takes a bit of time to load the value and get the better results and finally I'm gonna use this rear monitor using serial dot begin with about rate 115 200 and if you don't know how to use the Syrian monitor I highly recommend you to watch one of my videos I've talked about it in depth now we can move on to the loop function and each time we can get the temperature and put it inside a float which is a decimal number I'm gonna call it temp equals and then to get the value we use DHD dot read temperature and it Returns the value in Celsius and if you want to get the value in Fahrenheit you add true as a parameter I don't want that let's add another float I'm going to call it a humidity equals DHT dot read the humidity and it is in percent and finally let's display this information on the serial monitor using serial Dot print and I'm going to print the text tab then we add the actual value of the temperature using serial dot print and pass in the temp variable then we concatenate the unit using serial dot print it is the Celsius I will write C next we display the humidity using serial dot print I'm gonna write the text humidity then colon and we add the humidity value using serial.print humidity then we add the unit using the percent sign the same thing we have to add a delay so that we can get the accurate values like two seconds and here we have a loop function it is called over and over again we are going to display these values each two seconds but I will add print Ln at the end so that we can go back to the next line you see it's really simple to use this sensor with this Library dht.h now we can test our project of course you have to select the board I have a nodemcu32s and the port of the USB cable comes X and let's hit upload then I will hold down the boot key and once it's done uploading we can open up the serial monitor from this icon and it is this window of course make sure to select the word rate 115 200 and there you go we have the readings the temperature is about 18 Celsius and the humidity is 92 percent I think that's pretty much it guys for this video I hope you like it if you have any question or comment about this project make sure to write it under the comment section down below in the next video we'll create a DHT web server that allows you to get the values on your smartphone that's why don't forget to subscribe to my channel and hit the Bell icon that helps me a lot and I will see you in the next one
Info
Channel: Enjoy Mechatronics
Views: 67,946
Rating: undefined out of 5
Keywords: enjoy mechatronics, how to, microcontroller, lessons, getting started, esp32 beginners, esp32, introduction, esp8266, beginner, learn, sketch, sensors, basic tutorial, gpio, pin, basics, dht sensor, sensor, esp32 tutorial, esp32 arduino, arduino ide, randomnerdtutorials, random nerd tutorials, ESP32 dht11 with Arduino IDE, esp32 dht11, esp32 dht22, esp32 dht web server, dht sensor arduino, DHT11 sensor, temperature, humidity, Temperature Sensor, Humidity Sensor, dht sensor library
Id: K98h51XuqBE
Channel Id: undefined
Length: 6min 44sec (404 seconds)
Published: Tue Dec 13 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.