How to use ESP8266 NodeMCU with DHT11 Temperature and Humidity Sensor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys I share back in the video so in this video I am going to show you how you can use this esp8266 module or otherwise known as node MCU and use it with a DST 11 sensor over here so as you can see it is a quite tiny sensor and this video is actually very much compatible with your dht22 sensor so all I have to do is just change a few bits in the code and that will work with the DHD 22 sensor as well and I have also made the video with the esp32 board and as you can see this is the board right over here it is basically the same thing if you have watched that video just make sure that you connect the DHT sensor to the right pin and upload that code straight to this esp8266 board and that will work just fine but in this video for fresh starters I am going to show you how you can use that so let's get started the first thing that you may notice on the esp32 are the pins over here so as you can see there are no 5 volt pin on this ESP board over here because this is a 3.3 volt Port so it will only operate at 3.3 volts that doesn't really affect this sensor at all because you may have seen this sensor being used with arduino's and powered by the 5V Supply but this will also work on 3.3 volts so that's pretty nice so let's first connect our ground pin which is labeled as gnd over here as you can see and that will obviously go to the ground on the Android MCU in any ground pin you can connect it I am just going to connect it over here just like so as you can see now we'll connect the VCC pin which will be our positive power supply and that will go to the 3.3 volts in on the esp32 which is I think right over here just like so now we'll connect a data Pane and this is by far one of the most confusing thing I have seen in esp8266 board so the thing is actually if you look at the board over here as you can see all the pins are quite nicely labeled as you can see b0 D1 D2 D3 and so on also on the other side you can see but they don't actually represent anything if you look at the code I am not sure why they did that probably there would be some reason but I'm not sure if you look at the esp32 board then you can see we also have the same nomenclature with d and followed by a number so that will be our gpio pin which will be used in the code as you can see if I were to connect it to D13 over here or d27 or any other pin I will just write in 27 13 or whatever pin and we'll connect it but on the esp8266 we have a different case so the numbers printed on the board over here and the actual GPR pin are completely different so for example I have only remembered one pin the D2 pin you may assume that this is the GPI open number two but it is actually gpio pin number four so if you are struggling with your code just make sure that you check the gpio pin out of the node MCU over here because these pins will not help you at all so I will be connecting it to D2 but in the code we will use 4 because this is actually the gpio pin number four that's it for the connection with the node MCU and the DST 11 sensor now we will plug the micro USB cable into the slot over here connect it to our laptop and program it okay so we are in our Arduino IDE to upload this code but before we do that first we need to make sure that our ID can actually program our node MCU because by default it can only program Arduino boards obviously because this is Arduino IDE so what you have to do is just go to the file options over here and then click on preferences this will open up this window over here and in this window what you have to do is just paste this link over here I will give it in the description box below in the additional boards manager UL section and if you have any other code such as I have the esp32 on here as well you can just separate them by a comma over here as you can see and once that is done we can just go ahead and click on ok now we'll open up the boards manager which is this option over here as you can see the second one and in the filter search option you have to type in esp8266 and you will get this option over esp8266 by esp8266 Community just click on install I am getting this remove option because I have already installed it so this will install the all the boards and the libraries related to it as well and once that is done restart your ID and now we can finally go ahead and upload this code now talking about the code first as you can see we have included our library which is dht.h and to get this Library what you have to do is just go to the library section over here and type in dht11 make sure that there are no spaces and scroll down so you will find this Library over which is DHT sensor Library by awf as you can see this works for both dst11 and dst22 sensors so just again click on install I am getting this review portion because I have already installed it now in this section over here we have defined our pin and our type so as you know I have connected it to pin number D2 which is actually named as gpio pin number four so we'll use the 4 over here and obviously our type it is dst11 obviously if yours is 22 you can just replace the 11 by 22 just like this over here now we will Define it so this way the library know what type of sensor and in what pin we are going to use it then the setup function we are going to initialize the serial Monitor and start our DST in general as you can see now comes the main function which is the loop function as you can see we have added a delay of 2000 millisecond which turns out to be 2 seconds so every two seconds we will be getting the data from our sensor then three floating Point variable because as you know temperature is always measured to the first decimal so 34.5 36.5 so values beyond the point cannot be stored in integer type it can be only stored in flow that's why we are using float so we'll use the predefined function that is DHT dot read temperature and if you pass a parameter such as false that means it will give the readings in Celsius and if you pass the parameter true that means it is going to print in Fahrenheit and you can just leave it like this and it will by default print in Celsius but I have just given it over here for your future references it also gives us the humidity so same again as the temperature it is DHT dot read humidity and nothing to pass here all the values will be stored in tctf and hu so temperature in Celsius temperature in fahrenheit and humidity so we'll print them accordingly so first we'll print the temperature in C temperature in fahrenheit and then humidity obviously it is in percentage now we'll select our board and com Port so all you have to do is just go to this option over here select boards and ports and you don't have to type in here esp8266 because that won't turn up anything like so as you can see it doesn't show anything like that what you have to do is just type node MCU so you will get these three options over here mine is the node MC 1.0 esp12v module so I'll just select that and the com Port over here when you connect your ESP board to your laptop it will show up right over here so so in my case it is connected at com5 obviously if you are connecting it in your computer it may be different so just click on ok now all you have to do is just click on this button over here which will first compile the sketch and upload it to our board so as you can see now it says done uploading we can finally open up our serial monitor because as you know I am printing this on the serial monitor don't want to make this project any more complicated so just click on over here as you can see it is showing serial monitor so click on it and after some time as you can see we are now getting the readings so temperature 33.3 degree celsius 91 Fahrenheits or almost 92 Fahrenheit humidity is at 79 and hovering above 80 percent so to make sure that your sensor is working all you can do is just lightly blow on the sensor so I will just do that and as you can see immediately the temperature jumps up and we get a very high amount of humidity so that is how you can get the temperature readings in different formats and also the humidity from your DHT 11 sensor so that's how you can get the dst11 sensor reading via the esp8266 model and use it in your iot project so thanks for the new video guys hopefully you enjoyed it and if you have any thoughts or comments record this video you can comment down below I will try to answer them as soon as possible and also the circuit diagram and the code are in the description so you can check that out so until then I will see you all in the next one
Info
Channel: INOVATRIX
Views: 14,262
Rating: undefined out of 5
Keywords: #creative, #hobby, #inovation
Id: nLP6ArkNoO0
Channel Id: undefined
Length: 8min 26sec (506 seconds)
Published: Wed Sep 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.