Measure Temperature and Humidity WiFi with ESP32 DHT11 and DHT22 - Robojax

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we are going  to learn how to use DHT22   or DHT11 with esp32 to display the temperature  on the browser or on your mobile phone   or degree Celsius or display humidity and  percent I will show you the wiring diagram   I will show you the physical wiring the code will  be explained fully and I will demonstrate it hi   welcome to esp32 tutorial from Robojax my name  is Ahmad Shamshiri let's get started with this the larger screen click on this area of the player  so you can see all the chapters and then click to   move to that section of the video on your mobile  device you will see the menu when you touch it   you see all the chapters and touch  to move to that section of the video   when you want many times you need to measure  the temperature and humidity using these   sensors these are very famous and cheap so this  is dht11 and it's sold like that or like this this   has a resistor here at the back that is needed and  in this case I’m going to show you also how to put   a resistor this is very simple resistor I give  you also the value and the same way this dht22   is sold in this shape order ship it's exactly  the same uh the only thing is that you have   to know which one is it says and this one it says  ground and this one it says minus that's the same   here it says vcc here it says plus and then out  and here it says data but here it says out so   it's just a matter of how they labeled it but if  you know the two main pin the ground and plus then   you know the other one is output that you can read  and the code that I’ve written will work with all   esp32 so do not worry we just put it in 3.3 volts  and it is labeled clearly on the module which I’m   going to show you and also ground and then one pen  which you define any of digital pens it will work   in this case I’ve used pen two to use esp32 with  dht this is a esp32 development module we can have   dht11 dht21 or dht22 then we need to use them as  a web server and what is a web server for example   this is a web server where  you can type an ip address   and it gets connected to the web server and  the information is displayed on your computer and if you're using it over the internet not  in the same location for example when you type   robojax.com it goes over the internet to the web  server that is located somewhere on the internet   and the information will be displayed but at  home instead of the internet we have a router   and the web server is connected to the router to  this computer so we are connecting via the router   because the web server is also  connected to the router and your   laptop or mobile device is connected to the router  so web server acts like this and now instead of   the web server we can use esp32 as a web server  which means we send requests via the router and we   request some information from here it comes to our  screen for example if you have DHT11 information   is read by the esp32 it's sensor to the router and  from router on the screen you will see for example   the temperature the screen it can be also DHT22  or 21 the same way it will continue and instead of   laptop you can have your mobile device  that can display the temperature like this   if you're unable to read the temperature from dht  make sure to use code number two which prints only   on the serial monitor no wi-fi or no other thing  and also if you have still problem then if you   have Arduino uno or other Arduino then connect  the sensor directly with the code number two   so it can print it on the serial monitor and this  way you can be sure that the sensors are working   here is the wiring diagram for dht22 in this case if we have this module out is  connected to pin 2 plus is connected here to   3.3 volts and minus is connected to the ground  if you have this module if you're using dht11   plus is connected to 3.3 volts minus is connected  to the ground out is connected to pen two here if   you're using this module that does not have the  pcb we have four pins the left pin is connected   to 3.3 volts and here the last pen is connected  to the ground pen two is connected to second pen   from the left but from pin two to pin one  you just put a 5.6 to 10 kilo ohm resistor   just connect a resistor from this pin to this  one as you see it goes from that pin and comes   to this pin one resistor and here is the wiring  for dht 12 module from the left we have ground vcc   and out so ground will be connected to one of the  ground doesn't matter in this case I’ve connected   and here the last pin and then vcc is connected  to 3.3 volts and here the last pin on this side   and out I’ve defined here pin two so you can  define any other pen that has been connected   to pin two here number two which is which is  written here two and if you're using this module   usb on this side this is ground that's  three point three volts and then you choose   any of these pen and the code in this  case it's connected to pin two here sd2 and here for the dht11 the left and the plus  it is connected using red wire to 3.3 volts   and here and the right pin is ground, ground  is connected to one of the ground in this case   and this pen and then the middle one is  out, out is connected to pin number two here   using this module this is  d2 and 3.3 volts and ground   these two are the most important ones but you  can define any other pin you want in the code and if you're using the sensor like this without  pcb here I’ve connected one resistor between the   left pen it comes it goes to the second pen  so between this pen and this pen as shown here   from this pen resistor goes comes to the other  pen so pin one and pin two is connected using   this resistor on this module we have connected  to 3.3 volts lots of power ground and pin two   and here the left panel is connected to 3.3 volts  the second pin is output it is connected to pin   two here pin number two on this side and the third  pin is empty nothing is connected here you see   but the first pin this is ground ground have been  connected to ground in here if you're using this   module again we have 3.3 volts on ground and  pin 2 is in here SD2 or 2. if you're using   these two modules the wiring is exactly the  same so remove one and insert the other one   in order to start using esp32 with Arduino ide  you need to prepare Arduino ide for this purpose   you will copy and paste it here your css package  esp32 index.json at the end so once you paste it   here click ok click ok this is telling Arduino  ide where to get the board driver click on tools   and then board boards board manager and here wait  for this to complete at the bottom this bar graph and then type here esp32 you see esp32 by espresso  systems it says installed in your case it will not   be installed you will have install button here  click on it and it will take maybe a few seconds   or a minute and the installation once is completed  click close now we have to tell Arduino ide which   board you are working with because the driver is  ready click on tool boards this is Arduino ide   which you will usually work but scroll down until  you see a line below that all of these are esp32   and sp32 rover module is the one that you click  and select and the dot will appear now we have to   select the port for that we have to find out which  port we are using right click on the start menu   device manager and you see port click on this  arrow to collapse it and mine is using com ports   silicon lab if I disconnect it now you will  see that it will disappear connecting it back so this has come six note that click on tool   ports and you will see com6 is already selected  and now you can write your program and run it now let me explain the code the first thing you  need to do is install the library click on tools   go to manage libraries wait for this  to complete and then type here dht22 you will see here dht sensor library by adafruit  so once you install this this will work for   dht11 and dht22 modules in my case it  says installed you will see install here   you will see install something like this  in here click and install it in my case   it shows update and then close it this page  that you see here is generated by this esp32   so here is the code that we have this is the text  and browser is displaying it like that if I press   ctrl u I will see the code here and this has been  generated I’ve been generated here by the esp32   this is document type that is there we  have html and then head and then the title   and here it says meta refresh and then that's the  number that you see content so this is now three   that is refreshing the page every three seconds   so that's bringing from the code and  then after that we have head and body   as you can see this has been printed this  backslash and me newline it goes it brings this   piece down and then we have header one Robojax  dht code and here and then this is a paragraph   when you start a paragraph it always goes to the  next line so after the after this header it has   come in here and then we have paragraph stall  style font size 50 and then the text temperature   and then here this is a text that is coming  automatically if you have different languages   whatever you say for temperature it will be  displayed here and then the break is in here   it goes to the next line and then again  we have new paragraph with the color red   with a text size 50 which prints 28 degrees this  color red is that is being printed from here   and then we check if it is DHT11 then we  just need integer without decimal point else otherwise we have one decimal  place the temperature value   will be displayed and after that we  just have this uh unit Fahrenheit or   degrees Celsius degree Fahrenheit  whatever it is and then body and html is displayed here this variable is holding all  the elements so this is being added to page   this means add this into this so this portion is  added to page two now page is holding the whole   page and here we say server send with code and  200 of type text send the page the page is holding   the whole text this one and  browser is displaying it like this and here the code that I’ve used  is this code if you go on file   example and then web server under esp32 here it says web server and advanced web server so  this is from esp32 or m5 stack it's the same code   I’ve added this the refresh rate how many seconds  three seconds and then show serial if you want   to turn on the serial monitor this value that  displays it if you set it to false it will not   displace or change this to false and here we set  inside an unsigned integer zero, zero is Celsius   one for Fahrenheit and two for humidity if you  want and here we have title for three types we   have title so temperature humidity you can change  it to other languages as long as you keep the   quotation and then we have unit text this degree  this is degree Celsius whatever you put here this   is a unit for that and then degree Fahrenheit  we have separated them with comma so we have   three elements in this array of string and then we  have degrees Celsius degree Fahrenheit and percent   that's for humidity this is character but when you  make it as a reference it's a string and dht this   is adding the library for dht this is from library  and in this line we define the pen whichever pin   you are connecting and because I’m using pen two  and here or in this one whatever number it has   you just type the digit without the letters or  anything so then two here if you're using dht11 if you're using one of these then select dht11  remove this and comment the below but if you're   using but if you're using dht2 and t2 this module  doesn't matter the base but this is actual sensor   then comment the DHT11 and then uncomment the  dht22 and if you have dht21 which is am 2301 then   use this line so I’m using dht22 for this text  now for this demonstration and here we get the   library class create an object an instance of the  class and we call and we pass this pen in here and   then the type whatever it is we pass it to this  so yes it prepares the sensor and here we define   how we define the temperature value temperature  value in Fahrenheit and humidity as a type float   this was part of the code I have not changed it  here type your SSID for your router make sure that   upper and lower case is respected if I put this  lower case it will not work and then enter your   password inside this double quotation this is part  of the server definition this defines a server and   this is a function called center pressure this is  where it sends the temperature on the screen which   I’ve just explained it handle not found  this when you type something type here it   something forward slash with that number it is  not found it says forward slash 876. method type   get argument 0 so that's not found job of this  function is to handle the whatever request that is   not available and inside the setup we initialize  the sensor by using dht.begin this was part of   the code I have not changed it I have not changed  this this is just waiting until it gets connected   and here I’ve added this to it becomes a little  fancy it prints to the ip and here dh Robojax dht   so if I open this and then this press this reset  button pay attention reset it let me stop it so   it prints this so you can copy and paste or you  can go to this address let me copy and paste it   and go here so it prints that the wires are  not connected but you can access it like that   and this line sends a temperature with  a function explained separately and   I’ve added this I have not added this was part  of the code all of these are part of the code   inside the loop server handle client the job  of this is to handle all the requests that you   do or type and this line dht rate temperature it  reads the temperature in degree Celsius and we   store it in this variable called temperature value  and then humidity is stored in this humidity value   this is reading it and this is reading temperature  when you put hair through it reset in Fahrenheit   here we did not put anything inside this closing  and opening here we put through now it returns   Fahrenheit and we store it in variable called  temperature f value that's a Fahrenheit value   and here we check if the unit is equal one then  we say temperature is equal temperature Fahrenheit   if unit is three then we say temperature  value is equal humidity value   else mean if it is zero then the temperature  value is equal to pressure value the   actual Celsius and here we also check if  show serial is equal true print the value   the same way on the serial monitor  this was a full code explanation here is a demonstration to open the demonstration  first you have to make sure that you are connected   to the same wi-fi network that is defined in  the code as you can see here the wi-fi SSID   is Robojax and I am connected to Robojax now I’ve  selected the unit as degree Celsius and this line   I’ve uncommented that dht11 so this is active  now when I put these this line and this line   is now commented out so they are just comments  doing nothing this line is now active and then   I’ll make sure that two wires of the sensors  are not connected when you upload the code   if you get errors make sure go to  tools and here at the partition   select the manual and upload the code the code  is uploaded successfully then connect the wires and then open the serial monitor and if  you see this screen on the right side   come here at the bottom and select  hundreds fifteen thousand two hundred as you can see it is reading now  temperature now let's press reset button if I scroll down it will get connected and it  will tell me the ip address so this is the ip   address that I can get connected or you can go  also in majority of networks this should also work   Robojax dht so even if changes do not worry this  will work let's try this but if it doesn't work   for sure this will work so I’m going  at the address and then pasting it so   I’m pressing ctrl plus to increase the text so  you can see it this is displaying the temperature   and let's copy this and paste  it so you know both work   so it forwarded me back so here I’ve increased  the text now reducing it I’m pressing ctrl minus   or you can from here resize the  screen text now I’m applying some   so when you see this number it means  the wiring have been disconnected and here when you're using dht11 either this one  or this one if the wire is not connected you will   read something like this now I’m connecting it pay  attention in three seconds if when it refreshes you will read that temperature so let's  apply some heat using this heat gun as you can see the temperature  increased and the sensor is working on your mobile device make sure you are  connected to the same SSID in this case   Robojax I am connected and then type that by  ip address that you read on the serial monitor 1921680101 in my case and here this is a screen  I’m just increasing the text so you can see it   and here as you can see I can read it  also on my computer and on my mobile phone   slowly this will update refresh in three seconds  this and three seconds if they match you will   read the same thing if not it will be different  doesn't matter so every three seconds you get the temperature I have selected now the unit  to Celsius I have commented out the DHT11   and uncommented dht22 the code is being uploaded  the sensor is not connected as you can see   it is being uploaded it  takes a while half patience   and it is completed the same browser  the temperature is now showing   72.9 degrees Fahrenheit and if I disconnect  the wires in three seconds when it does when   this refreshes you will see this so we know that  this is now perfectly working and if I update it and now let's open it on my mobile  phone as you can see the same   temperature is also being displayed on  the mobile device let's apply some heat so it takes some time until the heat penetrates   so it is being updated and here my  mobile phone is also getting updated the wires are not connected and upload the code so code is being uploaded once this is done connect it back  and this will update as you can see   now we are reading the temperature from the  sensor and when I was heating it has been a little   deformed with temperature  but inside sensor is okay and here now my mobile device  is also showing humidity so perfectly working thank you for watching a  tutorial on esp32 if you learned something and   found this useful please thumb up as this will  help my video in the search algorithm of YouTube   if you have comment or question please  post it in the comment section below   I try to answer and reply if you haven't  subscribed to my channel please do so now let's turn it on again in this video I’m going to introduce the m5 stack  core 2 microcontroller unit this is based on esp32   it has 16 megabyte of ram eight megabyte of  sram it has two amps of touch screen built-in   wi-fi belts and Bluetooth it has microphone  speaker accelerometer and gyroscope microSD card   three programmable touch area  real-time clock it has vibration motor   has built and rechargeable lithium battery  and reset when I press it just reboots program this touch it quick power off and  power led usb c charge and control and all the   available expansion slots that are available for  esp32 60 millimeter 90 millimeters or less good   explain the schematic this is the main connector  that we connect everything the bus banggood has   sent me this product for review the link for the  product is below the video in the description
Info
Channel: Robojax
Views: 19,979
Rating: undefined out of 5
Keywords: electronic, tutorial, training, video, robojax, arduino, code, download, project, diy, robot, robotics, afghanistani, canadian, engineer, nejrab, ahmad, shamshiri, ontario, ajax, english, esp32, dht11, dht.h, dht21, dht22, temperature, humidity, mobile, phone, tablet, wifi, wiring, schematic, diagram, measure, ssid, ams2302, aosong
Id: JXCcmZUmzy8
Channel Id: undefined
Length: 29min 33sec (1773 seconds)
Published: Sun Apr 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.