hi welcome to an Arduino step-by-step course by Robojax
in order for you to successfully launch this and understand it first make a follow the video
and use only this one make sure to display the temperature on the serial monitor once it's done
then use only this one without the temperature sensor make sure you're able to display a text
on the lcd once that is done then you can use this code and both of these will easily work
now let me explain the wiring for this one we have four wires the four wires have been arranged uh
like this the from the left this is 3.3 volts have been connected to the 3.3 volts the second pin is
red have been connected to the ground and then this is sda the orange have been connected to a4
and scl the pin is connected to a5 using yellow wire this is ground the ground have been connected
to ground of Arduino at this point vcc is 5 volts using a white pin have been connected
here to 5 volts and then we have sda the gray have been connected to this is the a pin labeled here
using this wire sda and scl is the last one having connected to the last pin here in Arduino board
one is for adafruit htu 21df and the other is the liquid crystal underscore i2c I will provide you
the link you will download each separately a zip and follow this step for each you click on sketch
include library add dot zip library once you click you will point it to where you have saved
that zip file for example if this was your zip file you will browse and select it and click open
do this for both zip files after that close your Arduino meaning click close here and you see
here I have three instance of this close them all one by one make sure it's closed and then
reopen it now this is the code include wire.hs part of Arduino ide you don't need to download
anything it's already included this is the one that you have just downloaded this is the class
name and from this class we create an instance of that class as an object and we call it htu
including this line so the job of this line is to create this object which we will use later
then this is the beginning of and this is the liquid liquidcrystal.h using the include so this
is part of the library that you have downloaded in the next line we create the instance of this class
and we call it lcd it needs three parameter here the first parameter is the address the I score c
address of the device of your display and the 16 is number of character two is two line if
you have uh 20 character and four lines four lines you type here 20 and then make this four
now to get this address you need to run I2C
so copy and paste the sqrc in a blank sketch upload it to your Arduino
once it is uploaded make sure that temperature sensor is disconnected especially these two wires
that are five for I2C disconnect them because it will read the address for
this so we are making sure to get the address for this now I’m opening the serial monitor
you can click on tools serial monitor or press ctrl shift m here this will read the address
the address is 0x3f and I’ve already written it because I need it continuously in many tutorials
and if I connect the wire for this you will see that we will be reading one more I2C
address you see 0x3f you see 0x40 this is the address for this module now let's close this
and close the there type it here 0x refers to the hex value because we are referring the type
and this is actually three f is the address after this inside the setup we use lcd.begin
job of this one is to initialize the lcd backlight will initialize the backlight and then htu that's
for htu temperature dot begin this checks this means not if it is not initialized
then we print this on the screen and then in the next line which we go lcd dot set cursor to line
0 character 0 line 1 on this line and we say sensor missing and while 1 this while
true 1 is true while one while this is true stay here forever so the program will not
proceed further from this line else if that is not true which means the sensor is working then
we print this on the screen let me and then on the next line we print demo if I reset
by pressing the reset button on the Arduino you will see that it will print that with the
more this text is coming from there and then we give the user two seconds to read it and
we go to the loop this portion will run once inside the setup from here up to this end and
then the loop is the part of the code that will run continuously first we clear the screen from
the previous value which was there and then this is a function lcd which needs all these parameters
this is the opening and this is the closing you see when I put that you see the square around it
and it has all these parameters with comma the first one refers to line zero character
zero this is the first one is character zero line zero it goes up to this point and then we
print the text the Celsius after that we print this temperature which we go to character 10
if you see here if you count it 0 1 2 3 4 5 6 7 8 9 10 at 10 of line 0 and this line we use get htu
inside the quotation we put capital c this is getting the temperature which is this and then d
means degree will be printed so for the kelvin we do need but for the Celsius we want to press print
that degree symbols which look nice so from here to here is just on one line to display all these
values you just pass this parameter it will make it very easy which I’m going to explain it next
then the same way from here to here we'll do the Fahrenheit which is in the next line you see it
here and we print the degree symbol and then we wait five seconds after that we print this kelvin
now let's just wait for this Celsius Fahrenheit after this this is five seconds and then
we go to the line zero character zero print kelvin and then this time we print capital if
it is kelvin we print k and in the next line line 0 character 0 line 1 we print humidity
we put h get htu with h so you just need to put h it will convert it to
it will it will give you the h and then the percent is referring to this percent
so we can print it and we wait five seconds and the loop continuously doing the same thing now
two functions need to be explained get htu and then lcd display let me show you that get htu it
has a return type float which means a number with a diff with the decimal points and this k h or
c that you pass when arrives here it has a name called type we have a new variable
called value which will return this has not initialized we read the temperature here
and the temperature is stored in this variable called temp we read the humidity we store it in
this variable relative humidity and then we check if the type this type is capital f what we do is
we get the temperature which is here multiply it by this 9 over 5 plus 32 so this becomes
Fahrenheit when we store it into value or assign it to value if that is k the type here
we get the temperature in Celsius at 273.15 and this becomes kelvin when we store it here if it is
h we need humidity then we get relative humidity and pass it to this value so the value now has
relative humidity else means if none of this is true then it means Celsius so then the actual
temperature is assigned to this value and we use return dot value we'll get one of those according
to what we request here kh c or f Fahrenheit and this function display will get all those values
to make it simple you see we are printing this is the temperature character that is temperature row
from here those value that you pass the title will be printed on this and the second one will print
the value and after that we check if it is d the degree should be displayed print this car 2 2 3
this is printing that degree symbol and if it is percent we print the percent here for the kelvin
for the carbonyl print k now let me demonstrate I’m blowing hot air from this
so you will hear the bus but I’m gonna keep it away from the screen
now it's 96 degrees or 205 degrees Fahrenheit
very hot almost going to burn but I just removed the heater
80 degrees 190 degrees Fahrenheit
if I hold it my body temperature will bring it down let's see the humidity already increased
44 degrees please make sure to subscribe by clicking at the subscribe button in here
thank you thank you for watching tutorial from Robojax 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 at the comment section below
I try to answer and reply and don't forget to subscribe so you get updates on my upcoming videos