hi welcome to an Arduino step-by-step course by Robojax
in this lecture we are going to learn about this Bosch bmp280 barometric pressure
and temperature sensor we're going to have a look at the data sheet and then I’m going
to explain the code at the end I’m going to demonstrate the operation of this with Arduino
you can get this module as blue or purple from amazon eBay or AliExpress
this is bmp280 temperature sensor module that is the actual bmp 280 sensor and they provide
it as a module with this pin header I’m going to solder this on the module insert the header
into the breadboard so it can be held firmly then insert the module on top of it
and start soldering when you apply solder put your soldering iron on one side
of the pin and bring closer the solder from the other side as the pin gets hotter
the solder will be melted and it will be soldered properly and continue the same for all other pins
and this side we have labels here for the module vcc ground clock
they put a line here this c s c k and s c l one is used for spi the dot label and the other used
for I square c the c l means clock and c k also clock so that pin is clocked this pin
is data sda or s d I and then scb and sdo these are the other two pins that is needed for spi
let's have a look at the datasheet of bmp280 digital pressure sensor manufacturer is Bosch
here is a quick specification the pressure ranges from 300 to 1100 hectopascal relative accuracy is
plus minus 0.12 hectopascal absolute accuracy is typical plus minus 1. this consumes very little
current 2.7 microamperes at one health sampling so if you change the sampling rate it might increase
and the temperature range that this one can measure is minus 40 to 85 degrees Celsius and
here is a supply voltage is 3.6 that's the maximum we can go but it can also typically work with 1.8
volts as well I will provide the length for this data sheet in case if you need further information
let me now explain the wiring this is the module I’ve shown it here larger and this
is the color legend of these colors from this side vccs connectors we can use the 3.3 volts
this is 3.3 volts and ground has been connected to the ground the red wire from clock have been
connected to a5 and sda have been connected using this brown wire to a4 now the wiring on the module
if you solder your pin from the bottom and the sensor is at the top
from the left from this side vcc has been connected using the yellow wire to 3.3 volts
ground have been connected using the orange wire to the ground scl or clock wire have
been connected using this red wire to a5 and sda have been connected using this brown wire to a4
this is the page where you download the adafruit bmp280 library click on this
download and download zip point it to where you want to save it
now it's saved after that click on sketch include library point to add zip library
and then point it to the folder we have saved it I’ve saved it in this folder and here is a
bmp280 librarymaster.zip if you do not see that.zip that's also okay
as long as you see the icon that is not a regular folder it's a zip file
click also you can see here at the bottom it's zip so click ok open now the library has been included
close it and reopen your Arduino ide again this time click on file
example on the list somewhere at the bottom you will find it
add a fruit bmp to easy library and then there is only one example click on that and open it
running this just find out the address make sure the wiring and everything is correct make sure
the wiring is correct and you can get the I square c address for that purpose open
the I2C scanner that I provided the link you should have saved it and click and open that
I square c scanner upload it open the serial monitor you should see the address
0x76 so remember this address in case if we need it this tells us that the
module is connected properly that's a very important part and module is functional
let me explain the code the first line includes this wire.h file which is part of Arduino library
you don't have to do anything about this this is also part of Arduino ide but we are not using it
bmp280.8 is part of the library which I’ve just shown you these are all for the spi communication
this module can work with I sqlc and spi and we are using I square c if you're using spi
uncomment this one because we are using the I square c module this is working and these are
commented out inside the setup we initialize the serial monitor and then we print this text and
this line is to check if bmp began and if there is no issue and the communication happen between the
program and the device it will return true and using this exclamation mark we are checking if
it is not true if it is not true if there is an issue this text will be printed and it says
not valid and check the wiring and while one means stay forever and the program will stay here
and never proceed further this portion is bmp set sampling this sets the sampling rate of operation
inside the loop we are printing this text on the screen and then we read the temperature bmp dot
read temperature reads the temperature this is the actual value you can multiply it by
some number you can do mathematical calculation in it but in this case we are just printing it
and a little space and star or asterisk and then c so this will be printed immediately
after that and there will be a new line so this will print temperature and this line will print
pressure bmp dot read pressure and then this is in pascal the unit this will be another line and
this section will uh print approximate altitude based on your current location and pressure
this is called q and e or questionnil elevation which is used in aviation this is a an imaginary
flight level regardless of the sea based on that it prints your elevation and then we print a new
line the loop continuously printing the pressure and temperature and up your approximate elevation
and here is the issue when you upload your code first the default code that comes with you will
get this error it says could not find and that is the reason that the reason that the bmp has
not begun and if you go to your my document Arduino library and adafruit library master
you have to look at adafruit bmp280.h and open it and this file has here at line 36
it has an address for I square c 26 hex value so the value that we have is 76
even though 76 is on the left next line so let's change this to 76
and save now let's upload the code to open it and as you can see it works and here the code is
running as you can see it shows the temperature at 23.67 degrees Celsius and the pressure
98719 pascal and elevation shows 219. this is approximate we now apply heat using my heat gun
as you can see it shows incorrect value now and suddenly because it was above the value
now I have updated the code and I use my function that I’ve written before for the temperature
sensor and it prints in Fahrenheit Celsius and kelvin you just need to call get temp and inside
a single code just put capital letter of f for Fahrenheit c for centigrade and k for kelvin
and the code is in here change that I mean is bmp this is the line that is reading the actual
temperature and we are storing it in c as Celsius and this line is doing the calculation with c
and this will be Fahrenheit and if the type is f Fahrenheit we are returning the f
return f which means return this value and if the type is k we are returning c plus
this value which makes it kelvin and otherwise else means return c the original centigrade
would now be uploaded as you can see it shows Fahrenheit
centigrade kelvin and we have extra space in between each reading
let me hold this and see yes the temperature immediately increased to 27 degrees Celsius
28 please make sure to subscribe by clicking at the subscribe button
in here thank you thank you for watching 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 subscribe so you get updates on my upcoming videos