hi welcome Turner doing a tutorial from Robojax my name is Ahmad Shamshiri. I am from Canada
in this video we are going to learn how we can use BME 280 barometric pressure humidity and
temperature sensor and display it on a LCD 1602 or 2004 as degrees Celsius Fahrenheit Calvin and
also display the humidity approximate altitude in meter and also the pressure in hectopascal
you can get the code for this by clicking the link below the video in the description
which will take you to Robo Jack's comm slash learn flash Arduino let's get started with this
I've separate video explaining BMA 280 with complete detail explanation pins datasheet
and relative information you have to wash that and make sure that you can use it and understand
it I've also separate video for the LCD with I-square see module this has only four wires
so you have to wash that and download the code and make sure it works for both of these you need to
download the library once you are able to use the temperature sensor and display that temperature on
a serial monitor then that works try to use the LCD weather library and make sure that you are
able to display some kind of text on the LCD once you're succeeded with those two tasks then you can
come here and use this code and it will work fine and I have written this code specifically with two
different functions the first one is to get the temperature in different format because sometimes
people need and kelvin Celsius Fahrenheit and also the other parameters and also the I've
written another function for the LCD so you can easily display any of the parameters including
temperature in different formats and also the pressure humidity and approximate altitude all
of them with the way that you want it on the LCD including the degrees character the kelvin with
the unit at the end of it and that will make it very easy let us now get started with the wiring
if you need a wiring diagram for this I have a course at udemy.com which I've been teaching
or do we know and you can get all the library on the course and learn or do we know from beginner
to advanced from ground up in a structured course so you can get the wiring diagram for this project
as well the link will be available below the video let me explain the wiring if you hold
this temperature sensor and the sensor is at the top then from the left this is V n VN I've been
connected to 1012 which have been defined in code the second pin is ground ground I've been
connected to a ground of Arduino at this point understand is f CL and if the a SEL energy have
been connected in here which is defined at this pan so the sensor is connected on this left side
and have for this from the left we have ground ground I've been connected using black wire to
the ground of Arduino at this point VCC is connected to the five volts of Arduino and
then we have F da the gray have been connected to a four and SCL have been connected to a five
these two pins A4 and A5 or the I2C communication so we have I2C at this point a and here if you
don't have it you can put these wires connected to a breadboard and connect these together you
can connect up to 128 I2C devices on the same bus they will all work if you're using other devices
for example you know Ethernet if there is a 4 a 5 is a CL Arduino mega xx is d and 21 is SEL
and northern do there have been all mentioned I will provide you the link for this as well
let me explain the code you need to download the adafruit be me to ET library as a zip file
the link will be provided and also you need to download the liquid crystal underscore i2c you
need these two to be downloaded and installed so once you download them as a zip file you can
click on a sketch I'd include library and then add dot zip library and then point it to where
you have saved it for example if this was your zip click and select it and then click open after
that close this Arduino making sure that if you have multiple instance of this for example I have
for instance r5 close them all and then reopen it this line include wire.h is for I2C communication
for this device we needed but you don't need to download anything it's part of Arduino these two
are part of the BMP 280 library that you have to download and this define sea level pressure
hectopascal this is a standard value that we enter here is needed later for approximate
altitude calculation and then from this class or library we create an instance of it we call it BM
e and we refer to this as an object and throughout the code and here we also defined 2nd pin because
for the for this we need 5 volts and also for the sensor also we need 5 volts and Arduino uno
does not have to 5 volts so we have to define BM avian pin a pin for the VN so I've used pin
12 you can use any other digital pennis for this purpose then this is for liquid crystal include
and this which the library I just mentioned you have to download after that we are using this
class from the library and we create here an instance of it and we call it LCD this needs
three parameter this is the ice Percy address that is address for this module and if you are
not sure you can use I square CF scanner I will provide you the link you copy and paste it in a
new sketch and let me show you this as I scroll see you copy and paste it and then we are not
worried how it works just upload it to your board for example I'm now uploading it to this board
once it's done open the serial monitor by clicking here and
as you can see it shows to address one is for this
when it for this module which has been connected in here and the other one is for the for this
module let me disconnect the sensor so if I disconnect the sensor you will see that now
it will show only one address and the other one disappeared so 76 was for the module and 3f is
the address that I need let me disconnect the sensor so if I disconnect the sensor you will
see that now it will show only one address and the other one disappeared so 76 was for the module and
3f is the address that I need now I'm closing this and closing the SQL see uploading this code again
but 0x 3f was alder that I acquired from a CRC scanner enter it here 0x refers to hexadecimal
value it tells Arduino that this is a hex value and 3f is address 16 is the number of characters
16 + 2 is number of lines if you're using the larger if you are using this larger one 2004 you
have to enter 20 and then 0 4 here and 4 here not zero and then side the setup we use pin mode BM e
VN pin we define it as an output so the pin 12 is an output for example in this case this is as if I
type here 12 and then digital write BM e VN pin again pin 12 high so this will give and to have
always high and we have 5 volts for the sensor and sensor needs very little current so it's
okay to use it then Bull started is used without the code and we held this portion will do BM it
does began this initializes the sensor and if it is okay written works of true and the true will be
assigned to the status which we define here and then we check F status is not this means not if
it is not true it there is an issue apprentice on the screen and while one means stay here forever
it will not proceed further and then LCD dot begin initializes LCD under CD dot backlight initializes
a backlight LCD dot print warrant Robo Jack's video if I reset this you will see that it will
print these two lines death and that these are the two lines and it will give two seconds for
the viewer to see it and inside the loop we clear the screen from previous value and from here LCD
up to here we pass all this value for one line let me now explain it this zero means character zero
zero means line zero this is line 0 that's line one and we print this text Celsius death text
and after that this number and then dissemble and then we put here if you want a specific character
we can put that character but if you put nine nine I've written as such that no annoy means
the first available character at line zero well Trent this get BM e with single code see this
means get the Celsius temperature in Celsius and we need to have a degree symbol that D here refers
to this degree symbol and then after that we have the for Fahrenheit the same thing this goes
character zero line one and then nine nine means any available character after this text and then
at line one get it in Fahrenheit print also the degree symbol wait for 5 minutes 5 seconds and
then display clear the display after that Trent and Calvin lies 0 character 0 printed text Calvin
and then after that immediately get pressure and Calvin that death finger code came in Calvin also
print the character K at the end then this will do the humidity and get H that means this H means
get humidity and display the percent at N and here as you can see we wait for five seconds after that
we get the pressure with HPA and this line zero character zero is approximate altitude you see
here approximate altitude and I chose mm at the end this a means get altitude and we will five
seconds and the loop continuously doing the same thing now we need to explain this and we need to
explain LCD which I have written below when we use get DME and we pass one character here as a
k4 Calvin C for Celsius and all those different types we initialize a variable called value as
a type float and we read the temperature this is getting the temperature be a period temperature
this is in Celsius and we store it in a variable called temp that's type float now we have the
temperature in Celsius and we check if that type that we passed was capital F which means
Fahrenheit then get this temperature multiplied by 9 over 5 plus 32 this will be Celsius Fahrenheit
and assign it to the value that we define here so this value F it is f of the type is f we will
have Fahrenheit but it changes every is K then we add temperature plus 273 and it will be the Kelvin
this will be the Calvin assigned to the value and then if we have age then we get B ma Reid
humidity and it were assigned to the value F it is P which means pressure being a pressure
divided by hundred F this hundred means divided by hundred of type float F means
it is float it's not otherwise it will be treated as double so because all the rest
of the values are float this will be fruit and we will assign it to the value every is a which
means altitude then B M a real altitude and we passed this variable which we define the sea
level pressure and hectopascal the value will be there and else means if there is no sea we
see we did not mention capital C it means F it is C or Celsius then get the actual temperature and
assign it to a value and then return the value whatever the value is based on the character
so this will return the value that's why this will get the value this will be just a number
now LCD have multiple characters this is the temperature character temperature row and then
title for example there's Calvin for example you see this pressure or all those so this is
the text of the title and then we have the value this is a tie title and this is a value then we
have value character value row which row and then we have the actual value the value character is a
position this is also positioned this is actual value and then at the end we have assemble K or
% or anything we are passing it and we said the temperature or the text characters text row we set
it and we put on the title that we have so this whole trend this portion up to the collar and then
we check if it is not nine nine then we said the character and then we print the value this value
automatically whatever value this or that and then LCD print car two two three this two to three is
now an integer if we put car in front of it become it's called casting we are converting this type to
character and that causes this degree symbol does round that you saw here else assemble as percent
we print the percent if it is small K we parent capital K if it is small T we print HPA every
if M we print M accordingly this these at the end and that's it so this was explanation of the code
Heather demonstration is shows pressures and hectopascal and approximate altitude degrees
Celsius with sample this is 44 degrees and Fahrenheit and Kelvin with decay and humidity
was present everything looks perfect but the for example the altitude we have one extra
digit every is more than we have to remove we have to reduce this text size and because
this sensor can go up to 85 degrees Celsius and not more than that it is always enough because
two digit was fed here I know if it increases the Celsius and Fahrenheit will show properly
let's see degrees Celsius 74 degrees 165 and as you saw the value have moved to the left I
would like to sincerely thank the following people who have supported me via patreon
you
thank you for watching this was how to display the temperature and other parameters from BM e
to ET temperature barometric pressure and humidity sensor on the LCD screen if you learn something
and found this useful please stamp up it will help the video and the algorithm of search and
also if you have comment or question posted a comment section below I try to answer and
reply if you haven't subscribed so far please do so you can grab this of my upcoming videos