How to use BME280 Temperature, Humidity and Pressure sensor with Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to an arduino tutorial from robojax my name is ahmad shamshiri i'm presenting this video from canada in this video we are going to learn how we can use the bosch bme 280 pressure relative humidity and temperature sensor with arduino you can get the code for this by clicking at the link below the video in the description which will take you to robojax.com learn arduino let's get started with this when you purchase this module from ebay aliexpress or other sources or amazon they will ship it with a pen header if the pen header is not there you just insert here four pens and we will solder it this is the actual bme 280 module we have here some pens these are to select different square c address which we are not going to touch and here vn this will be connected to 5 volts ground scl and sda scl is a clock sda is the data this will be used for i square c communication and on this one if we zoom in it says 6 2 2 and here if we zoom in this is the three pin regulator 6x2 here is a data sheet for it it is a low dropout cmos voltage regulator the maximum current that can give this 300 250 milliamp and the highest voltage that can reach 6.5 volts what it means is that we can connect this to 5 volts and it will work fine and we have different versions of that so this must be 3.3 volts which i'm going to measure the voltage let's measure the voltage in this pin on the right side that is the output and here on the data sheet it shows the output and we're going to measure between ground and this pen this is also ground and this is the output this is the input that third pin from that side i have put the pin the negative is connected on the left side and if i connect it to the right you will see it's 3.3 volts and the second component here this is a sex pen it is a power supply monitor it has been labeled as 702 this is the item 702 and here's the data sheet for it it's low dropout regulator here are the pens as you can see sex pen this is the package i'll provide you the link for this let's have a look at the data sheet for bme 280 here is the key features of it the operating voltage is 1.71 to 3.6 volts that's why we have a regulator so we can connect to 5 volts up to 5 volts and the current that it consumes for humidity pressure humidity humidity pressure and temperature these are 1.8 micron per 2.8 and 3.6 microampere respectively operating range is for temperature minus 40 to 85 degrees so it doesn't go above because this is for [Music] environment for human environment use and relative humidity zero to 100 percent and pressure 300 to 1100 hectopascal i will provide you the link in case if you need further information from this if you need a wiring diagram for this it will be available as part of my arduino course on udemy the link will be provided below the video let me explain the wiring if you see the sensor at the top these are the pens which i'm gonna explain this pen is vcc this has been connected to five volts of arduino the second pen is ground ground have been connected using red to the ground this is scl orange orange has been connected to a5 and the yellow is sd8 it has been connected to a4 you can also connect it to these two pens sdl and cl which have been labeled they are exactly the same in terms of communication let me now explain the code the first thing that you need to do is download the library the link will be provided once you download it you will have it as a zip file save it on your computer then go to sketch include library add dot web library and then browse to the place you have saved the zip file for example if this was your library select it and click open once you do that close your arduino and also make sure for example i have two instances of arduino close both of them and then reopen it after that go to file example you should see adafruit bme280 library and click bme to et test and this is the code there are a lot of extra codes for example spi you do need it because we are using i square c the wire is enough and these two pieces are needed none of these are needed because these are for ice spi communication so you can delete them this is sea level pressure hectopascal value which is approximate sea level elevation calculation and this line add a fruit bme to 80 bme that's for i square c which has no uh forward slash so this is now active these are deactivated these are five i square c communication these two lines you can delete it if you want and unsigned delay time there is some delay time that is used of type long we set inside the setup we set the 9600 bot for the serial monitor using serial.begin and that is the value when you open the serial monitor you will see it on the right corner you will see it in in here is math match and then we print bme to et this is just a text in the flash memory bme dot begin it will return true if it is working and the value will be stored here otherwise it will be false because it's boolean and then we check if status is true and this means not if it is not true then we print this on the screen that says it could not found and while one means stay here forever and the program will stop at this point will not proceed if this doesn't happen we print this text and the delay is one 000 millisecond and we print this line and inside the loop we have print values and delay time this delay that you set one second will be applied here and prints value so the loop will continuously execute this function the function is here and starts from this point ends in here this line prints the text temperature on the screen and this line gets the value this is actual temperature and we pass it to this to the screen so we'll print the temperature and then this degree in this store with the c and then we print the pressure this line is getting the pressure and divided by 100 and this f means treat this as float not double and we are dividing it by hundred to get hecto pascal and also the unit is hpa we are printing the text beside it then approximate altitude this is approximate our altitude is 90 and you will see that it shows something different i was checking it through google google map and then using bme read altitude and we pass the value that have been defined above this will return the approximate altitude this tree will print humidity this is the title this is actually bme read humidity this will print the value with a percent at the end and this prints new line so between all these values there is an extra break let me upload this let me open this you will see that it is printing the temperature let me stop it so you can see it so it prints the temperature the current temperature in my room the pressure in hectopascal approximate altitude it shows 60.63 while our city ajax ontario is 90 meters above the sea level so so they use the word approximate so do not rely on this much humidity is 45.61 and it continuously prince does that i have this heat gun here master craft i will apply some heat to this and we will see the value here as you can see the temperature shows 62 degrees 60 degrees celsius the humidity drops significantly and as the temperature is reduced the humidity increases the pressure is almost the same very little change and here is a custom code that i've written so it can be used easily after this portion is exactly the same inside the setup i've removed the delay the setup is the same inside the loop we have like this we are printing this text temperature equal and then serial i've written this function get bme and then inside the single code we pass c if you want celsius you pass c if you want fahrenheit pass f for kelvin pass k if you want pressure put p and if you on humidity put h for altitude put a so we this is returning the value and it is being printed and then we print the degree the degree series here symbol a needs special track i've written another function it's at the bottom of this screen which i'm going to explain i'm going to explain this as well and then we print this c after the symbol we parent the c and then we have a letter of space and then get temperature and we get it in fahrenheit because many times you might need it in fahrenheit so i created this code that anything that you need it should accommodate and then we print degree symbol print f and space and then we also print kelvin we don't need a degree for the kelvin we print k at the end and then this is new line after printing all the temperature and different celsius fahrenheit and kelvin we have ln this creates new line and this is creating a next line we print pressure simply using get bme and inside single quote we put capital p pressure and with a space hpa then we print humidity with h or the printing percent and then altitude with this function on m and then we create a new line and we wait two seconds and that loop continuously doing the same now to explain this i'm going to explain it here this is called get bme and we pass a character if you pass k for calvin c for celsius it will come here and will be called type and we create a new float value through variable called value and we read all the four parameters here read temperature bmi.3 temperature which was printing before now we store it in a variable called temp and we did pressure same line that from previous code we store it in a variable called pressure humidity we call we store it in a variable called rel humidity and bme and this is the approximate altitude we store it in alt and then we check the type if type is equal equal this is for comparison purpose if it is f fahrenheit we get the temperature multiplied by 9 over 5 plus 32 this will be fahrenheit and store to this value that we define f that that this type character is kelvin we add to original temperature which is this one we add 273.15 and this will be our kelvin and the value will be now kelvin not this one because the f condition will take care of it and if it is humidity we put relative humidity into h and if it is pressure we assign pressure to the value and if it is a altitude we put alt to the value else mean if it is celsius then actual temperature will be to the value and we use return.value which will return the value according to the selection that the function has received and then print degree this is printing the degree symbol on the screen we need the hex character of c2 and b0 to side by side this will create a symbol for degrees degree symbol either celsius or fahrenheit here's a demonstration of custom code that i have written when you run this it prints degrees celsius degrees fahrenheit kelvin and then the rest that you've seen it will be printed the same way i've made it very simple and here let's say you want to take action if the temperature in celsius this c means celsius this is the value is greater than 65.2 degrees let's say you're monitoring a liquid temperature or a device temperature if it is getting hot you will turn on a fan or a cooler then if it is greater than that then opening and closing it here and you can take some action here for example turning on a fan or whatever or let's say digital write and pen five high of course pin five has to be defined as an output above but this was just an example so you can send a signal to a pen and the fan will turn on or or you can turn it off or if or you can do the opposite whatever you want if the temperature is below this then do that so this is action i'm commenting this out this will not do anything so you get the idea if you want fahrenheit just change the fahrenheit change it to fahrenheit pressure or any other value that you want i would like to sincerely thank the following people who have supported me via patreon thank you for watching this was how to use the bme to eat it temperature sensor if you found the video useful or learned something please thumb up if you have comment or question post it at the comment section below i always try to answer a reply to get updates of my upcoming videos you may subscribe now you
Info
Channel: Robojax
Views: 37,980
Rating: undefined out of 5
Keywords: electronic, tutorial, training, video, robojax, arduino, code, download, bme280, temperature, humidity, pressure, sensor, how to, display, serial monitor, Celsius, Kelvin, Fahrenheit, Humidity, Pressure, Altitude
Id: 7dwWYn9_OhA
Channel Id: undefined
Length: 17min 23sec (1043 seconds)
Published: Wed Jul 31 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.