In this video lesson I show you how you can create a project for measuring altitude using an arduino and a BMP180 Pressure Sensor. We go through the physics, math, circuit and coding to make this project work. For our example, we are using a GY-87 module, which has a BMP180 sensor on it. If you are using a BMP180 sensor directly, it should work the same. For your convenience, this is the circuit schematic we will be using:
For your convenience, the code we developed in the video lesson above is included below. Enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#include <Adafruit_BMP085.h> Adafruit_BMP085 BP; bool BMPconnected; bool haveBase = false; float basePressure; float Height = 0; float HeightNow=0; void setup() { // put your setup code here, to run once: Serial.begin(9600); BMPconnected = BP.begin(); if (BMPconnected == true) { Serial.println("BMP180 Found and Connected."); } if (BMPconnected == false) { Serial.println("BMP180 Not Found! Check Connections."); } } void loop() { // put your main code here, to run repeatedly: if (haveBase==false){ Serial.println("Place Device at Base, Enter Go:"); while (Serial.available()==0){ } basePressure=BP.readPressure(); haveBase = true; } HeightNow = findHeight(basePressure); Height= .95*Height + .05*HeightNow; Serial.print(5); Serial.print(","); Serial.print(-5); Serial.print(","); Serial.print(HeightNow); Serial.print(","); Serial.println(Height); delay(10); } float findHeight(float p0){ float d; float T0 =288.15; float L =.0065; float R = 8.3144598; float M = .0289644; float g = 9.8; float pH; pH=BP.readPressure(); float c=R*L/(M*g); d = T0/L*(1 - pow((pH/p0), c )); d = d * 3.28084; return d; } |