Arduino Tutorial 50: How to Connect and Use the DHT11 Temperature and Humidity Sensor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is polemic order from top tech boy comm and we are here today with lesson number 50 in our legendary new and improved series of Arduino tutorials and what we are going to learn today is we are going to learn how to use the dht11 temperature and humidity sensor and i'm going to give you guys a heads up this is a pretty easy sensor to use but I am using this series of videos it's going to be kind of a series of videos on this dht11 and so I'm going to give you guys a heads up that you know I've always promised that what we do in this series you can all do with the components in the oligo super starter kit and so all of these tutorials that I'm doing or based on the components in this in the good news is the dht11 sensor is in here and you can continue through these next lessons using only what is in that kit but I'm going to give you a heads up of kind of where we're going we're trying to untether from the desktop computer where we can start developing a little system that we could walk around with well what are we going to need to do if we're going to be able to walk around with this we're gonna need to be able to power the Arduino not plugged into the computer and we're gonna need to be able to have some sort of standalone display on the board and then we're going to need to be able to get everything hooked up now you will be able to do this with the sensor I mean with the Arduino the sensor and the components that came in the kit but as we start doing more complicated stuff it would be good if you could get a couple of other things the all these links are down in the description below at a minimum you need the e Lego kit a couple of things that would be nice is a little larger prototyping board a little larger breadboard a link to a one to one that I like an amazon link down in the description below also as we start getting more and more and more wires as the project gets more complicated you need one of these little kits with these elegant little short jumper wires you don't want to continue to use these these long wires like this that is you build things with lots of connections you're going to have a lot more look if you plug things into this bigger board and you use the shorter neater wires okay one more thing I hope you can get again if all you have is the lead a Lego kit you can make all of this work with just the e Lego kits but as we're moving forward in future directions on this dht11 project it would be nice if you had one of these little Arduino nanos and what you can see the Nano is it's like a smaller version of the Arduino okay and if you get the the Nano version of the Arduino you see what I can do is I can plug it into this board and then I can plug the other things into the board and then it's much easier to get something I can walk around with now if you're running jumpers from the normal Arduino Uno over to your board and you're just using these types of wires as you walk around probably you're going to have things shaking loose so if all you have is the e Lego great but if you want to really completely do things right you want to get one of these Arduino nanos and you want to get the larger breadboard and you want to get the more elegant wires what I will do is all this stuff that I'm giving you a heads up on for future or lessons you can find in the links down below and don't hate me because I tell you what you need all right a lot of times I get a lot of hate over that but okay another introduction let's go ahead and move forward and getting this thing hooked up half the battle on this particular project is getting the library installed all the things that we've done so far in these tutorials the libraries are already included with the standard download of the arduino ide so all you got to do is do this pound include in your code you don't have to actually go install the library well for the dht11 this will be the first time that you actually have to install a library and so that means you will get to learn something you will learn something today ok so let's see first thing we need to do is get the library and I need to go to a better view here alright I think you can see that and what you just search on is dht11 space arduino space library you want the library and then it looks like the second one down is a site called WW Arduino libraries info and so the major heading is DHT sensor library Arduino libraries I'm going to click there and then here you can see all of these and you can see that it's kind of periodically updated as of the time I am making this video the last release date is February 18th of 2019 so I'm going to hit and go ahead and get that when I click on this notice that it downloads as a zip file and so if you look down here in my lower left if you're on Google Chrome when I click this you can see down there the download start and in fact it goes pretty quickly now you have to understand this is a zip file you can't take the zip folder and put it in your library folder you've got to open the zip folder ok and then here you can see my open zip folder and then let me make a little room I'm trying to continue to do this where you can see everything and then where did my zip folder go ok so this is the zip folder and then you look at the contents of the zip folder and it's a DHT since her library I'm going to take this and I'm going to drag it and drop it to my desktop ok now I am going to kill this zip window this is what I pulled out of the zip window now we have to go and install the library so we will come back to our Arduino okay now you have to kind of figure out where your particular Arduino sketch book is and the way you do that is you come under file and you look at preferences okay and for me months and see users Paul in documents in Arduino alright so now I need to kill this and I need to go there so I'm going to open another folder here File Explorer okay and where did I want to go well it was documents and then it was Arduino okay and then what do I want I want libraries well if you look mine is already there but let's delete it I will delete that pretend that you didn't see that that it wasn't there and then you come over and you get this unzipped folder and you drag it and drop it into your libraries folder okay and now it's there and so now you should have the library installed so we learned something new today we learned how to install a library key thing is to be able to find out where your add we know software was was loaded in that we did by preference and then looking at the sketchbook location so now we should have a library and so let's just check that if I just do a pound include and then the library name is DHT dot H like that okay that's that's interesting this include is a little bit different let's let's go ahead and download that and see if it likes it okay it recognizes it I don't know why I used to we would go like this I think I wonder if there's really a difference I'm learning in real time along with you that seems to like that as well so so maybe either either way would work but what you don't do is you don't put a semicolon on the end so where are we here we are able to load the library so what do we need to do now what we need to do now is we need to hook up our we need to hook up our temperature and pressure sensor according to this bond out and I am wondering if I can real quickly add no let me just let me just show you that that when you're looking at it the pin on your left will go to pin 2 and then the center pin is 5 volts and the right pin is going to be ground ok so it's going to go pin to VCC and grout or pin to 5 volts and ground so let's see if we can look over here and do that alright so you can play along with me here and what I'm going to do is I'm going to plug it in like this so you can see it and then what did we say we said that the left pin these are looking on on it like this this first pin is going to be what the first pin is going to be 10 to so we are going to go to the Arduino and go to pin 2 this I think is important you can't just use any pin you really need to use pin 2 because we've got some stuff going on with the libraries and then what is next we have the center pin hooked to 5 volts okay and I am going to start over I am going to use a white wire from the center white wire from the center to okay left goes to pin 2 there's a reason that I'm so confused today left okay do you see that the left of the three pins there's three pins the left one goes to pin two what I got off on is I like to use a red wire which is the center one which is going to go to the five volts on the Arduino so right five volts on the Arduino goes to the center and then that leaves the ground pin and looking for a black ground pin wire that is long enough I don't so I use a blue one okay so the right pin the rightmost pin okay blue is going to go to G and D all right so we will review when you are looking at it as I had it oriented in the overhead camera left is Green Center is red and the right goes to ground so left is to Center goes to five volts and right goes to ground all right so let's come back over here I think we have this hooked up now looks nice now what we have to do is we got to start writing some code and so I need to go to a nice code view for you and let's see if this one is going to work I believe this one will work right so first thing you have to do is you have to include the library how do we include the library we include the library by saying pound include pound include and then the open triangular capital D H th you have to type it exactly like that now we've got to provide some more information next we have to tell it what type we have so we set a constant we haven't done this before because I really don't like using constants even theirs though there's reasons to use them we can define a constant a constant is like a variable but that never changes and you do that by define this is saying that I'm going to make this a constant and the word the constant that I want is type and then what type is at dht11 why is it dht11 because that is the sensor that we are using this is the dht11 there's several other similar devices that you can use with this library but we're using the dht11 and then we've got a hat tell it where we connected it int since pin where did we connect this we connected it to pin 2 all right that looks pretty good what else do we need to do well we have to create the object we have to create the object and we are going to use create what type of object the DHT okay and then what am I going to call it I'm going to call it HT so the object is HT and so when I interact with it I'm going to interact with HT and this is coming from the DHT library now I have to tell it two things its sense in when I create the object it's got to know where it's connected and then the type which we set up as a constant above all right that looks pretty good now we got to set up our variables float this device will measure humidity so we'll say humidity float it will measure temp C centigrade temperature float it will measure temp why are we using floats well our temperatures are ways round numbers no they're not relative humidity is not a round number they can be the in between numbers so that's what we are going to do then we come down to our void set up we always need to start almost always start with serial monitor serial dot begin 9600 okay HT dot begin so we're gonna start you know we we set up the object we created the object up here the HT object now we have to start it we have to begin its HT dot again and then anytime I do something like this with the library I'm not exactly sure of an a component I'm not exactly sure of I like to just put in a delay just like let's call it set time just to get make sure that you give everything time to set up sometimes you don't really know what's going on in there so I'll say int set time and we'll set it to 500 which would be half a second that looks pretty good now in our loop what do we want to do B we want to read humidity so that would be humidity is equal to humidity is equal to what's our object HT and then what do we want to do you want to read humidity I did something wrong read humidity why is it not recognizing that do you think that it really wants the quotes here you see it should when I get down here it should recognize read humidity I am somewhat perplexed read humidity let's just see if I can even download that now that is okay it seemed to be happy with that I'm just I'm a little unclear why it didn't recognize recognize that as a command perhaps later we will find out what's wrong float temp I mean 10 C is equal to H T dot read temp temperature turn it it recognizes that okay let's go temp F is equal to H T dot read temperature and this you say true true what true that you want to read in Fahrenheit so this really is kind of crazy I would have thought you know the parameter would have been F and the other one C or the other one should have been false but this is just the way it works okay you would not be able to believe how much it bothers me that we are not able to do this okay let me give you one other heads up if this isn't working like if it's not finding the library sometimes you when you install a new library you have to kill Arduino and then reopen Arduino and then it will find the library so if it's not finding your library kill Arduino and then reopen it and it should work okay this is just perplexing me when it's not finding Reed humidity unless I am in some crazy way not spelling that right which has been known to happen okay so now let's uh let's do some prints here we are going to say serial dot print and what am I going to print I am going to print humidity this is a string so this is just going to be a label and seer print and then I'm going to print what I read as humidity and then I'm going to put my semicolons in better late than never on that serial dot print and now I am going to print and I'll put a space there temperature C space put good spaces in there so that this looks good when it prints out and then serial dot print and then this is temp see better late than never on a semicolon and print does start with a P serial dot print space C space and then serial dot print and then temp f10 F and then serial dot print yes println we are done and this is space space I have no idea what that's going to do okay so we've got that going let me get further out of your way and let's see if this crazy thing is going to work you can see right here behind me is the serial monitor so when we run this thing you will see I'm going to take a shot of coffee this is crazy okay everyone hold your breath boom it downloaded let's call up the serial monitor and see what oh look at that we are getting some numbers here okay one thing is is that this is running crazy I need to put a delay in there so I'm gonna put a delay and I'll just see I'll just say DT for delay time okay I will come back up here and I will say int delay time equals let's put 1000 like that and let's download it again I hate having things run past the serial monitor that fast and you can actually run into problems if you're printing faster than you can do things okay so let's see I'm gonna hit the reset button here and start over and I'm going to say clear output I want to get a humidity is 50 for temperature see 26 this this I probably you guys probably caught this but I said temperature see and then I put a C on the end of it so I'll just say temperature like that and then let's start this over okay humidity is 53 temperature is 26 C and 79 oh man we got this thing working temperature pressure on the serial monitor very good very very very good most excellent most excellent so you see this sensor is pretty easy to use the thing that you've just got to do is you've got to install the library that's the main thing and you've got to be careful when you install that library right you open the zip you drag the folder out of the zip onto your desktop you get rid of the zip folder and then you drag it into that library folder and to do that into the library folder you gotta know where your sketchbook is and you do that by looking at preferences and if you do that then you can do it everything let's see if this actually works like let me let me blow on it and see if I can get the temperature to go up well if I blow on it really the temperature and the the temperature and the humidity should go up look at that humidity did go up and let's see temperature didn't change much yeah temperature went up a little bit but man oh yeah temperature went up and the humidity really went up now the question is after breathing on it do you have a little bit of a condensation thing like is it going to take a second for the humidity to go back down my feeling is probably yes because if you actually blow on something the humidity can take a little while to go back down but what we can clearly see is we can see that the temperature the temperature and F and the and the temperature and C are going are going down and so we can see that kind of interesting that you know perhaps when you blow on it like that okay the humidity is now starting to come down and so that's good starting to drop pretty good now but you can imagine that just your breath on there if if if the condensation was on there it would take a little while for that to come off and so that is pretty exciting that is pretty exciting so this has been my goodness what lesson is this this is like lesson number lesson number fifty and so I need to give you an assignment for lesson number 51 what is our goal here our goal is to become mobile to become untethered and so if we are going to become untethered one of the first things that you're going to have to do is you're going to have to put an LCD display on there and so your assignment for number 50 is to hook this up with an LCD display and the LCD display just do humidity and temperature F like on the first line you can do humidity and then on the second line you can use temperature F and then also I will tell you guys that as I'm trying to get ready to be going mobile next week I'm going to be doing this with the Nano now you don't have to do it with the Nano you can do it with the Lego but this is kind of like what I'm going to be doing I am going to be trying to get this here like this and then this here like this okay and then the cents are there and then you see how neatly I'm gonna try to wire between the Arduino Nano and the LCD with the sensor there also remember with this LCD display you're going to have to have the potentiometer and so you are going to I think we're quickly going to be hitting the limits of what all we can hook to the to this board hence my desire for you to get the larger PC board in the at the link below okay so at a minimum in lesson number 50 I want you to have the Arduino the LCD in the sensor hooked up and then displaying your results to the to the LCD and if you are able to get your hands on a nano so you can have a little bit more sturdy connection because you see the problem is going to be if you're moving this around and something comes loose then you're going to start getting you're gonna start getting bad data and so we're gonna try to go to those neater circuit builds okay this has been Palma quarter from top tech boy go.com you guys your assignment I've given you your Sun would also think about giving me a thumbs up think about sharing this with other people what I'm really hoping is I'm hoping we can begin to kind of build a community of people that like to work together on these projects and you can see my videos are a little long because I do it with you right we're we kind of work on this together and I I might sound like I'm rambling but I'm just talking out loud how I thought when I was an engineer right I spent my career as a as a very successful engineer so as I'm going through these videos I'm talking out loud how I would think through things when I was working as an engineer okay Palmer quarter from top tech boy comm go get your homework done come back next week and let's see how you did I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 74,285
Rating: undefined out of 5
Keywords: DHT11, Temperature, Humidity, Arduino
Id: -AvF2TsB2GI
Channel Id: undefined
Length: 29min 1sec (1741 seconds)
Published: Tue Feb 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.