How to Measure Altitude with the Arduino - Ultimate Guide to the Arduino #40

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] in the last video we used the bmp-180 barometric pressure sensor to measure atmospheric pressure and temperature in this video we're going to use it to measure altitude having a way to measure altitude is essential in drones remote controlled airplanes and weather balloons altitude measurements can also supplement GPS data maps and navigation tools atmospheric pressure changes depending on your altitude think back to that column of air we talked about in the last video this one inch by one inch column of air rises from the surface of the Earth to the very edge of the atmosphere if you're standing on the ground beneath this column you would feel the pressure of one atmosphere or 14.7 pounds per square inch now imagine you're in an airplane or at the top of a really high mountain now there's less air above you and less air mass pressing down on you so the atmospheric pressure would be less than one atmosphere this relationship between altitude and atmospheric pressure is what allows us to measure altitude with the bmp-180 the bmp-180 can detect very small changes in atmospheric pressure it's so sensitive in fact that we can use it to measure altitude with an accuracy of just a few inches the relationship between atmospheric pressure and altitude looks like this the y-axis shows the pressure in hectopascals and the x-axis shows altitude in kilometers at very low altitudes the pressure is near 1013 hectopascals the pressure decreases along this curve until it reaches zero at the very top of the atmosphere this curve follows an equation called the international barometric formula National barometric formula solves for altitude as a function of pressure we only need to know two things to solve for altitude p which is the atmospheric pressure at your current location this will be measured by the bmp-180 and P0 which is the atmospheric pressure at some base level the pressure used for P0 depends on where you want to measure the altitude from if you want to know your altitude from sea level you can use the atmospheric pressure at sea level you might do this if you're measuring altitude for navigation or mapping purposes or to track your elevation along a trail if you want to know your altitude from the ground you can use the atmospheric pressure measured from the ground at your current location you might use this measurement if you're building a weather balloon or drone where you want to know the height of the sensor off the ground the atmospheric pressure at sea level can be found a couple different ways the most accurate way is to use the bmp-180 to measure it and I'll show you how to do that in a little bit but you can also find maps online they will tell you the atmospheric pressure at sea level for your current location the atmospheric pressure measured from ground can be found using the bmp-180 pressure measurement taken at ground level I'll show you how to do that too we're going to connect the BMP 180 to the Arduino just like we did in the last video the SDA pin on the sensor connects to Arduino pin A4 and the scl pin on the sensor connects to pin A5 ground connects to ground and the VCC pin of the sensor can connect to either 3.3 volts or 5 volts remember if you're using another type of Arduino board the i2c pins might be in different locations okay now let's look at an example sketch that outputs the altitude of this sensor from sea level or from the ground most of the sketch is identical to the sketch we saw in the barometric pressure and temperature video we still need to include the libraries and create a BMP 180 object then we declare a float variable called P0 which holds the P0 pressure in hectopascals this is where you put the barometric pressure at the point you want to measure the altitude from if you want to measure the altitude from sea level enter the barometric pressure at sea level here I'll show you how to measure that with a BMP 180 in a couple minutes if you want to measure the altitude relative to the ground enter the barometric pressure of your current location close to the ground use the barometric pressure sketch from the last video to get that I'm going to measure altitude relative to the ground in this example so a few minutes ago I put my BMP 180 on the ground and measured the pressure this is the value I got in the setup we initialize the serial Monitor and the sensor in the loop all of the variables are the same except for this double variable called out will hold the altitude measurements we still need all these if statements to get the temperature and pressure readings from the sensor in the last if statement we use the altitude function that comes with the BMP 180 Library this function takes two arguments the first argument is p the pressure measured by the bmp-180 the second argument is P0 which is either your ground level pressure or your sea level pressure depending on where you want the altitude measured from the altitude function takes these parameters and runs them through the international barometric formula we saw earlier to get a value for the altitude in meters the result of that calculation is stored in the alt variable now all we have to do is print out the results first we serial print the word altitude then we print the out variable and finally we print the word meters and end the line okay let's check this out so I have my BMP 180 connected here we're already getting some altitude measurements coming through I have my Arduino on a table right now which is about one meter off the ground so these numbers are about right all right so this is my altitude from the ground since I set my P0 equal to the pressure I measured close to ground level now I'm going to show you how to measure altitude relative to sea level sea level pressure is the pressure at your current altitude that's been adjusted to make it look like it was taken at sea level using sea level pressure removes the effective altitude from your barometric pressure measurements so even if you live far away from the ocean you can still find a sea level pressure for your exact location to calculate it you just need to know your altitude sea level pressure is calculated with the same International barometric formula we saw earlier it's just been rearranged to solve for P0 P0 is the sea level pressure at your current location is still the pressure measured by the bmp-180 an altitude is the altitude at your current location I'd recommend using a phone app to find your current altitude they're easy to use and pretty accurate too otherwise sites like elevationmap.net will detect your location and give you an altitude measurement the sketch for finding your sea level pressure is very similar to the altitude sketch there are just a few differences here we declare float variable called out which holds the altitude of your location in meters this is where you put the altitude measurement you got online or from your phone app in the loop we have a new double variable called sea level pressure which will hold the sea level pressure measurement in the last if statement we use the c-level function provided by the bmp180 library this function uses the international barometric formula to calculate the sea level pressure we pass the P variable as the argument which holds the pressure measured by the bmp-180 then we pass it the alt variable which holds your current altitude now we print out the result to the serial monitor so now take this measurement and use it for P0 in the altitude sketch we saw earlier and that will give you your altitude relative to sea level in the next video we're going to look at digital magnetometers magnetometers detect magnetic fields and can be used as digital compasses they're perfect for projects that use navigation and guidance systems [Music] the three in one smart car and iot learning kit from Sun founder is a Hands-On all included Electronics kit that is perfect for anyone who wants to learn how to master the Arduino the kit comes with an Arduino 22 different sensors and modules thread boards jumper wires and everything else you need to build a bunch of fun and interesting projects learn about robotics by building a remote controlled smart car that can be controlled with an infrared remote controller or drive on its own and avoid obstacles or fall on the line learn about the internet of things with a project that lets you monitor the temperature humidity and light level of a room from an app on your smartphone [Music] and build a plant monitor that tracks the temperature humidity light intensity and soil moisture and displays it on your smartphone so you can keep your plants water remotely it's a super cool kit and I have lots of fun building all the projects in it so click the link in the description below to order the kit from Sun founder
Info
Channel: Circuit Basics
Views: 6,507
Rating: undefined out of 5
Keywords: arduino, raspberry pi, circuit projects, electronics projects, circuits, circuit basics, arduino projects, raspberry pi projects, IOT, robotics
Id: vg025C4H_KI
Channel Id: undefined
Length: 11min 29sec (689 seconds)
Published: Thu Jul 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.