Want to send me something? Technivorous 902 n Hughes Blunt Sd 57522
All right folks, welcome to Arduino for Beginners. This is Arduino 101.
Today we are taking a look at this little guy. Now this is HW507. This is a DHT device, DHT11,
and in fact this is a temperature and humidity gauge. So we're going to be using the serial
output on our Arduino software here to put out the temperature and humidity around that little
device there. However, we are going to need a few other things. One of the things I have here
is a 10k resistor. That's going to be necessary, as well as three female to male jumper cables,
and one male to male jumper cable. I do have my Arduino already wired into the 5 volt,
so we're going to leave that just like that for now. But as you can see on this side of the screen,
I am missing a library. So this is where I was talking about earlier in the library video that
sometimes you need additional things. In order to get this library, I'm going to go to manage library
and I'm just going to type in DHT. Now this is a library specifically made for this device
and to use all its components. So again, why would we do it from scratch
when we can find what we're looking for by searching here? Usually it is the case where
it's something that we can find. However, this library is not showing up. Actually it is,
it's just a little bit further down here. So this is the one we're looking for by Adafruit
and it is for the DHT11, which is what we're using. So let's hit install on that.
And yes, we want to install the missing dependencies as well, which will also install
another library that that library uses. So that makes sure we have all the files that we need in
our chain there. Gave me a null pointer exception for some reason. So all right, now it's updating,
it's downloaded, it's closed. I should be able to compile this and I'm still getting an error.
Let's see if it says the library is installed. Type that in there again, go down and no,
it's saying install. So that is the latest version. Install all, updating list of installed
libraries. This time we didn't get that error. So hopefully it worked. Let's try again compiling.
And it seems to be compiling. So I think it's working now. Although our sketch, if we export
it now, isn't going to do anything for us. So first we need to connect to our Arduino board.
As I said, I already have the positive and negative hooked in here. So we can go ahead
and just jump over and hook those in. And they are the middle and the far left piece here. So
I did that backwards. No, it was right. It doesn't really matter. I like to try and keep the colors
organized so I know what's hot and what's not. So basically we are going to go right to
the hot side here. And we're going to take the return side to the return.
My jumper cable needs a little work here. It seems to be malfunctioning.
There we go. And then we are going to actually use this resistor here
to connect to the positive as well. So we're right beside that red wire there.
And then we are going to do something a little bit different.
And that is we are going to take the last pin here, which is the signal pin,
and we're going to plug it into that resistor pin there. Which I'm actually going to move over a
couple here. There we go. Plug that in there. And then we are going to jump from this side of it
to a pin on our Arduino. And let's pick number two since I believe that's the one in the code here.
And now that we have it all wired up we should be able to turn this guy on and get a readout.
So let's hit play and then we'll go over the code real quick. I want to see if this
uploads properly and works as advertised. So
can open device com nine. Oh well it helps if you plug it in.
Let's try that again. Upload. And the only way we're going to get output here
is by using the serial monitor. So now that it's done uploading it should be running.
Let's open the serial monitor and get that into view. And I am getting a failed to read.
Alright well it was a simple fix. Actually as I said when I read the number off of my
DHT it is actually right under there. It says DHT 11. And under define up here DHT type in that DHT
file was being defined as DHT 22. So I simply changed that to 11. And now we should be ready
to go. So we'll upload one more time. Upload. Upload. Upload. Done uploading. So should be
ready to run. Let's grab that serial monitor and bring it back into view one more time.
And there we have it. Humidity around the sensor is 58 percent. Temperature is 27-26 degrees
Celsius or 80 degrees Fahrenheit. So there are ways to manipulate that. Let's see how long it
takes. So the humidity is climbing. That is because I have my hand over the sensor so it's
detecting moisture from my hand as well. I can remove that and it should simply go back down.
We'll take a minute for it to dissipate. There you can see it going back down. So
this sensor is also very very useful for a ton of things. You can do a lot of cool things with it.
Let's take a look at the code real quick before we end this video so you can kind of see what's
going on here. So a lot of this is pretty self-explanatory. We are using our library.
We are including DHT and then we are going to instantiate an instance of DHT called DHT.
And with that we are going to do our work on the processor itself. But first we're going to go into
our setup loop. We're going to type in serial.begin 9600. That's basically the bond rate we're using
to communicate with the serial port listener. And then we are going to hit serial.printline
and it's going to run our DHT test. Now we're going to change this to 11. You could use a
variable to change that to an instance of whatever we have defined here and make it update automatically
but we don't need to do that right now. Then we are going to hit DHT begin. Now once that's begun
we're going to enter our void loop here and we're going to start off with a delay of two seconds.
That's 2000. And then we are going to instantiate three floats and those are going to be the
humidity, the temperature, and the temperature in Fahrenheit. So basically then we are going to run
a check to make sure that things are uh it is non means is not a number so if h is not a number or
t is not a number or f is not a number meaning one of these sensors returned a value that was not a
number it is going to print failed to read and we did get that failed to read when we had it set to
22 up here because it was using the wrong part of the library so after that we are going to return
out of there and it will just continue to run and printing failed to read every time it runs this
loop and we are going to add two different floats and this one is actually this is heating Fahrenheit
and this is heat in Celsius and it's going to use a part of the DHT file which computes the
heat index and will tell you the temperature of the things that you are looking for so
these need to be typed in just as they are and you do need this false here at the end of that
call to the compute heat index method so then basically every time we get the results for
what we are doing and then we make sure it is a number if it is not a number we stop printing
anything or we stop reading it and then print that fail and then if it is a number it will
continue on and it will compute what the temperature is from the data that it is receiving from the
sensor and then here we are going to print it all out to the serial monitor so this is all going to
print in a row when it says serial.print every single line is going to come out lined up and
then when it says serial.print line it is going to print a separate line and then it is going to
end the line meaning that you can't print right after it again so it's going to continue running
this over and over again and as you can see it is still going it is fairly accurate as far as
what the temperature is and things like that so this is a very very useful sensor and as I've
said before about all these sensors if you'd like to get a hold of one of these definitely check out
the affiliate links I have down below you can get a whole grip of them for cheap on banggood.com
so pretty good stuff we are going to pack it up for this tutorial and move on to the next one
well that's it guys that's going to wrap up this video if you've noticed a shirt the merch is
available go ahead and check out the teespring merch link down below it won't be available on
a channel store until I reach 10,000 subscribers and so far I am just about to hit 5,000 so it'll
be a little while a couple more months before you see this on the actual channel but they are
available now I have a couple other designs feel free to pop over there and check them out and know
that any purchase through the teespring site definitely helps to promote our site here and
increase the channel's ability to make videos in the future so we appreciate all your support don't
forget to check out the teespring link check out our patreon link leave a like on this video and
hit that subscribe button because we have a lot more coming at you in the coming days