Arduino Tutorial 25- Portable Temperature and Humidity Sensor with DHT11

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey welcome back everyone in this new tutorial we are going to make a project that summarized what we have covered in the earlier lessons which is a portable humidity and temperature sensor as you can see we are going to use the lcd display and the dht sensor to get the temperature and the humidity then we are going to display the values using this lcd you see that the temperature is 28 celsius and the humidity is 33 percent and this project work independently i am powering the arduino using this battery you could put all of these components inside a small box and you will have a portable temperature and a humidity sensor so if this is the first time you're visiting my channel make sure to hit the subscribe button and the notifications bell so that you don't miss my next videos and let's jump right into it so to make this project you will need the lcd display which we have talked about in the previous video i'm using the one that comes with the i2c module because it's easier to use of course you need the arduino uno or any board you have like the nano if you are using the arduino nano it's going to work also you need the dht sensor we are using this to read the temperature and the humidity values of course you need few wires and this male to female jumper wire to connect the lcd display to the arduino and if you didn't watch my previous videos about the lcd display or the dht sensor make sure to check it out i'm gonna add the links under the video description first we're going to connect all of these components and let's start with the dht sensor basically we need to create a 5 volts rail because we need to power this module with a 5 volts and the lcd display as well but i'm going to create a 5 volts rail and a ground rail as well and that's very easy we need to connect the 5 volts of the arduino to one of the points i'm gonna use this red line and now you could use all of these points as five volts and with the same way we can create a ground rail i'm going to connect the ground pin to one of the points on the other line now we have a ground rail and a 5 volts array and let's start by powering this module as you can see we have three pens we have the gnd we are going to connect it to the gnd and the vcc to the 5 volts then we are going to use the middle leg to read the temperature and the humidity it's labeled data so let's hook it up i'm going to take this blue wire and let's go from the gnd pin to one of these ground points and the vcc for me it's on the right side to the 5 volts and you see that we have this red led that is turned on and finally we need to connect the data pin which is in the middle to one of the digital pens i'm going to use the pin number two to read the data then let's connect our lcd display so if you don't know we are using this i2c module this allows you to connect the lcd using four panes and we have this potentiometer to adjust the brightness so we're going to connect the gnd to the gnd and the vcc to the 5 volts then we have the sda and the scl pens the sda needs to be connected to a4 and the scl to a5 you could check out the table that i'm going to put on the screen you could also use these two pens and if you don't have these two pens you could use a4 for the sda and a5 for the scl so let's connect our four pins the brown wire is gnd the red one is vcc then we have the sda it's the orange wire and scl is the yellow wire and let's start by connecting the gnd which is the brown wire then the vcc and you see that we have this led and that's how we can power this lcd but to control the text we need to connect the sda and sel pans we have the sda is orange i'm gonna connect it to this pin so this one is labeled sda and the left pin is labeled scl now we've connected all of the components we can move to the arduino ide but first you need to make sure that you have the two libraries we have a library that is called dht to control the dht sensor and the liquidity crystal i2c library as well and to install these libraries you can go to tools then manage libraries the first one is called dht sensor library and we've already installed this library make sure to press the install button if you didn't also we need the liquid crystal i2c just search for this library then you could find it down below make sure to check for this name liquid crystal i2c which is made by marco schwartz for me it's already installed let's close this window now we can write the code first we need to load our libraries using the include command the first one is dht then dot h and the second library is liquid crystal then underscore i to c then we can add dot h make sure to add that now we need to create two objects the first one is the dht so this is a new type that comes from this library and let's call this variable dht and here we need to pass in two parameters the first one is the pin that we are using which is connected to the data pane i'm using the pin number two then we need to add the type of this sensor and it's dht11 if you are using a different dht sensor make sure to put the type there is another type called dht22 then let's add the semicolon also we need two variables to store the temperature and the humidity you could use a float but you could also use an int i'm gonna call the first one temp to store the temperature and let's call the other one humidity then we need to begin this dht variable under this setup we need to add dht dot begin and under the loop function we can read the temperature and the humidity but before that we need to wait for two seconds because this sensor needs a little bit of time to get the accurate value using the delay function we could pass in 2000 or you could create another variable for this time i'm gonna call it dt or delay time then let's assign two thousand i highly recommend you to use variables all the time after that we can read the temperature using dht dot read temperature and this temperature is in celsius if you want to get the value in fahrenheit you could pass in through but i'm going to leave it as default in celsius we can store it in our temp variable then we can read the humidity using the function dht dot read humidity but make sure to assign it to the humidity variable now we need to display these values using our lcd and to do that we need to create an lcd object the type is liquid crystal underscore i2c then let's call it lcd so these are called objects you could call them variables but the right name is object then we have to pass in three parameters the first one is the address basically each i2c module has an address that we need to pass in for me i'm using this one which is 0x3f but if it doesn't work for you you could use 0x27 we have 16 columns and 2 rows if you have a different display make sure to put the right size then we need to go under the setup function and write lcd dot init which means initialize then we need to turn on the backlight so these lcds work with a backlight and to do that we use the backlight method now we can use our lcd to display the temperature and the humidity but first of all we need to set the cursor i'm going to write the temperature in the first line so we need to use lcd dot set cursor we need to move it to zero zero that means the first line and the first column now we can write the temperature using the print function or print method let's pass same temperature or temp then colon and that's going to write this string after that we can put the value of the temperature using lcd dot print you don't need to change the position of the cursor it will change automatically at the end of this string and that's what we want let's pass in the temp value and finally we can add the unit which is the celsius using lcd.print and let's pass in the string c and with the same way we can write the humidity but first of all we need to change the cursor to the next line using lcd.set cursor and the position is the bottom left corner which is the column number zero and the line number one then with the same way we can write the humidity using lcd dot print and let's write humidity then colon and let's close the string after that i'm gonna write the actual value which is stored under the humidity variable and finally we can add the unit which is the percent using print and i'm going to add this percent sign and that's pretty much it now we can test our code but first of all i'm gonna verify it maybe we have few mistakes and yeah everything is all right we can upload the code and there you go we have the temperature it's 29c and the humidity is 37 percent so i think that's pretty much it guys for this video i hope you like it if you have any question or comment make sure to write it under the comment section down below and before i finish this video now you could unplug the arduino uno from the computer and use this battery and i recommend you to use the 12 volts because this lcd needs a little bit of power and you could power it through this cable and if you have other ideas about a project make sure to write it under the comment section down below so that we can create a video about it and they will see you in the next one [Music] you
Info
Channel: Enjoy Mechatronics
Views: 28,216
Rating: undefined out of 5
Keywords: tutorial, enjoy mechatronics, how to, microcontroller, lessons, arduino uno, electronics, programming, DHT11 sensor arduino, arduino, sensor, DHT11, Temperature Sensor, Humidity Sensor, measure humidity using Arduino, dht11 arduino code, arduino dht11 project, arduino lcd, arduino lcd i2c, i2c, module, display, lcd, arduino display, arduino with lcd tutorial, arduino lcd code, connect lcd, circuits, dht11 humidity sensor, arduino dht11 tutorial, fun arduino project, cool arduino project
Id: 880UQUgUD2M
Channel Id: undefined
Length: 13min 28sec (808 seconds)
Published: Fri Dec 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.