ESP32 Tutorial 51 - Temperatuer and Humidty over WiFi with DHT | SunFounder's ESP32 IoT Learning kit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to iot tutorial from Robojax in this  video we're going to use the SunFounder’s esp32   with es sp32 extension board to use dht11 or  dht22 to measure the temperature and humidity   on your mobile device or on the browser let's  get started with this esp32 starter kit from   Sounder this is the best esp32 learning kit from  s founder it has this esp32 microcontroller which   has built-in Wi-Fi and Bluetooth this board can  do everything Arduino Uno can do or many other   Arduinos can do plus extra more features because  we have Wi-Fi and Bluetooth the possibilities are   endless you can get connected to the cloud or  do the control or read information or values   via your mobile device or your desktop  or over the cloud from a far location it comes with a camera extension kit where  you can stream the video over Wi-Fi either   through the cloud or to your network and  also it comes with micro SD card where you   can save images on the micro SD card or you can  write from the device any information log the   information on the device and read it back  you can power the board using this included   18650 lithium battery and it has built-in  charger where you can connect micro USB   and charge the battery the kit comes with 320  pieces of component that you can learn tons of projects this is an Internet of Things when  the device connected to the internet and   provide information or being controlled over the  Internet they are called internet of things and   this is internet of things to tutorial I've  already learned how to use DHT temperature   sensor with esp32 and esp32 extension board  the link for that video is below this video   If you haven't seen it in that video we learn  also how to install the library which I'm not   going to repeat it here please watch that video  so you can install the library but in this video   we are going to use the Wi-Fi feature of esp32  and now this is acting as a web server and it   has an IP address and we are using our  mobile device or a browser we can access   the IP address and read the temperature from via  this p32 so the temperature is measured here and   this is propagating it via Wi-Fi and we have been  connected to the same network and we are reading   it and here also this is connected to the same  network as this one so this is the most critical   part when we connect this to our to your router  what whatever is this ID is this phone must be   connected to the same router otherwise you will  not be able to see it and if you get out of your   house or building then you cannot measure it  for that you need a separate solution so you   can find out the IP address I assume that you  already have prepared and downloaded all the   required software that I mentioned it in lesson  one if you have not watched it please watch that   video and also if you have not watched that  DHT temperature sensor video tutorial please   watch it so you learn how to install the  library for this otherwise this will not work come to this page docs.sunFounder.com  scroll down until you see esp32 then click   on esp32 starter kit main on  the left side click on Arduino user I've started this code from uh the example that  is located and in files example and under the   esp32 just scroll down until you see web server  and advanced web server this was the code that I   have initially started it and modified it for  our purpose I will provide do this code we are   defining a refresh value how fast the information  is being updated 3 seconds is still very fast it   should be at least 10 seconds of type integer and  constant and then show serial if you set this to   false it will not display any information here  let me open the serial monitor you see it shows   the temperature and if I close it we don't need  it at the moment so you can set this to false uh   if you don't need it and here this is the unit we  if you want Celsius just type zero and if you want   Fahrenheit type one so this is for that purpose  and these are the text for this is the temperature   title for Celsius the temperature title for  Fahrenheit and the humidity title if if you   speak other than English you can type your text  here make sure to respect this double quotation   and your text should not include double quotation  or the unit for C has Fahrenheit and percent do   not change this this is including the DHT Library  this is the pen that is used by DHT Library which   is pin 14 and this is DHT 11 if you want to use  dht22 just change this to dht22 or comment this   line like this and uncomment this line and it  will work for DHT uh 22 now from the library of   DHT we create a and an object called DHT with  lower DH and T and we are passing the pen and   the type and these are the variables that are  holding temperature value temperature F value   which is Fahrenheit and humidity value please do  these are the code needed for the esp32 to work   as a Wi-Fi client web server and msDNS ESP mdnf  do not change them type your SS ID for your Wi-Fi   for example like that and then type the password  please make sure that SSID is case sensitive for   example if you have if your SSID is book with  capital B if you type lower case b it will not   work so uh pay attention to that and here we're  from web server we are initializing our server   at Port 80 this is a function that uh sense  the temperature on the screen this screen is coming from this function and we create a  string called page and this is a doc type   and then the next line page this page we  are adding to this page which is started   from this value and this we we are adding  uh line by line more stuff to it so we   are concatenating and this this is the title  that you see that is this title the refresh   is coming here do not change anything  here and this is the text Robojax DHT code which is this code and then we check if the DHT type is equal  DHT 11 we just print the temperature as integer   else if it's not DHT 11 then it's dht22 then  we type it with a with one decimal point add   it to this page and then we put the unit which  is degrees Celsius in here and then we have a   break this portion is for humidity we put the  title and the value for the humidity and the   unit which is a percent symbol and that is  done and then the body and HTML is added to   page and here we use server. send 200 200 is  an okay request and this is a type text HTML   and the page that has all the information  is sent and this is just sending the page   this line handle not found is a function  that if you type something different on   the code you will get it let me show you for  example at the end if you type here forward flashbook this is the the answer and this is  handling it handle not found and it says URL   method argument and then something not found  will be displayed so we are creating message   and sending it as a server with 404 code as a  plain text that's why not found an for/ book   and get an argument so this was taken care  of that inside the setup we initialize that   DHT with DHT do begin this is initializing the  serial monitor this is initializing the Wi-Fi   and we are passing SS ID and password and this is  just printing this new line on the screen while   Wi-Fi status is not equal Wi-Fi link connected  if it's not connected then we have delay 500   millisecond and then we print this dot so this  will continue until it is connected and this is   equal false because initially it needs some time  to connect so the number of dots shows how many   seconds we have waited until it's connected and  then we have this text and then we are printing   connected to and then we type the SSID on the  screen and then we print uh this text and then   at the end we print in this IP address after that  and we say to read temperature and mdns begin we   can also access it using Robojax DHT instead of  IP address and paste that enter it did not work   so let's put HTTP colum SL SL and then DHT as you  can see we are able to read it without even typing   the address so this is the that DNS that we typed  and then this is the most important line that say   server on rout when it when this is the request  there is nothing after forward slash then send   temperature which is was a function at the top  of the code that I mentioned and if server inline   anything if you just type inline for/ inline it  will print it will print this text let's test it and here let's put it forward slash end line here it says this works as well so so this was taken care of that line and  server on not found it goes to this function   which I just shown you and then server. begin  is initializing the server and this will print   this HTTP server started on the serial Monitor  and inside the loop we we initialize server.   handle client so this it must be inside the loop  and then we read DHT do temperature we read uh   degrees Celsius and store it in a variable called  temperature value and we use DHT do humidity and   a variable called DHT humidity which we defined  it at the top of the code these three have been   defined at the top and this is temperature f for  f so we call DHT re temperature true so this will   convert it to Fahrenheit so we have three values  and if we have show serial then it will print the   temperature with a unit on the screen uh this  text and then if it is DHT 11 we will type the   temperature if if it is dht22 we print it with one  decimal place and then this prints new line and we   have 300 millisecond delay and the r will continue  does all these task over again you want to change   and if you don't need a humidity this is humidity  from there to here just remove it and it will be fine or if you don't need that temperature  then uh then remove this this text keep this   p and remove up to here so remove all of this  and if you would need it you will get just humidity now let's see how we can select the esp32  board we can click here under the select board and   type here esp32 de as soon as you type Dev you  will see Dev board you can select it and click   okay so the board have been selected now we have  to select the port the other way to select the   board is Click On Tools board esp32 and select  the esp32 dev module now we have to select the   port if I click here it shows two port and I don't  know which one belongs to my device sometimes you   will see you will not see the number properly  so the best way to be sure the right click on   the start menu go to the device manager and you  will see here the ports if I click on this Arrow   it will show me the ports and is USB serial  ch340 one the other is USB serial device and   here now it's connected if I disconnect this one  of them disappear the one that disappeared is my board so six stays and it disappeared if I connect it so it is my comport ch340 now it is my  comport and I can select it or I can can   click on tool port and here you will see it you  can select whichever you want ours is com8 now   we have successfully selected the board and the  port and this is very important it must be done first and here's a demonstration uh the  Wi-Fi is connected to the same SS ID as   this phone otherwise you will not be  able to see it and the same way your   computer the same way your computer should be  connected to the same network as as the as the esp32 I'm clicking on this button to upload it  the code have been uploaded now I'm pressing   this button now and you will see let's stop  this and it says that the IP address is 192.168.0.1 03 so this is the uh IP  address that we are going to copy and   paste right click or maybe just copy so  we're going to this address and here the   the IP address that I visited is 19216801  03 and the code is being refreshed every 3   seconds and this is now in Fahrenheit if we  want to change it to Celsius we could do so and here we can change the unit here we will make  this one to zero 0er means Celsius and upload the code upload this completed the IP address has not changed and and here the unit has has changed to Celsius and here I've connected my mobile  phone to 192168 0103 and I can read the   temperature here on this screen I can put  them side by side so you can see it on the   same time on the mobile device and on your  browser either your PC or tablet whatever   you have you can see that now let me get a heat  gun I will apply some heat let's see if it goes higher so pay attention this is every 3 [Applause]  seconds and as you can see the temperature has   increased and this one is also showing 50° and  20% humidity or 25 now you see one is lagging   in a few seconds so this was started a different  time but every 3 seconds we can get a refreshed value that
Info
Channel: Robojax
Views: 1,145
Rating: undefined out of 5
Keywords: robojax, sun, founder, sunfounder, course, tutorial, kit, learn, learning, step by step, esp32, arduino, iot, wifi, web server, measure, temperature, humidity, sensor, dht, dht11, dht22, dispaly, browser, mobile, phone, tablet
Id: drrW1EHqKuM
Channel Id: undefined
Length: 18min 44sec (1124 seconds)
Published: Fri Dec 29 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.