In this video lesson we create a portable altimeter that measures altitude above a base reference location. The device uses an arduino uno R4 Wifi, a BMP180 pressure sensor which is on the GY-87 module. For your convenience, we present the circuit diagram used below:

This is the code for this project, for your convenience.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <Adafruit_BMP085.h> Adafruit_BMP085 BP; bool BMPconnected; bool haveBase = false; int butPin = 2; int butVal = 1; int butValOld = 1; float basePressure; float Height = 0; float HeightNow = 0; int feet; int inches; int screenWidth = 128; int screenHeight = 64; int oledReset = -1; #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 oled(screenWidth, screenHeight, &Wire, oledReset); void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(butPin, INPUT_PULLUP); delay(250); BMPconnected = BP.begin(); if (BMPconnected == true) { Serial.println("BMP180 Found and Connected."); } if (BMPconnected == false) { Serial.println("BMP180 Not Found! Check Connections."); } oled.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); oled.clearDisplay(); oled.setCursor(0, 12); oled.setTextColor(WHITE); oled.setTextSize(1); oled.println("Place the Deluxe "); oled.println("HeightOmatic at"); oled.println("Base Location, and"); oled.println("Press Go!"); oled.display(); } void loop() { // put your main code here, to run repeatedly: butVal = digitalRead(butPin); if (butVal == 1 && butValOld == 0) { basePressure=0; oled.clearDisplay(); oled.setCursor(0,12); oled.setTextSize(1); oled.setTextColor(WHITE); oled.println("WAIT . . ."); oled.display(); for (int i=1;i<=100;i=i+1){ basePressure=basePressure + BP.readPressure(); } basePressure = basePressure/100; haveBase = true; } butValOld = butVal; if (haveBase == true) { HeightNow = findHeight(basePressure); Height = .95 * Height + .05 * HeightNow; feet = Height; inches = (Height - feet) * 12; oled.clearDisplay(); oled.setCursor(0, 12); oled.setTextColor(WHITE); oled.setTextSize(1); oled.print(feet); oled.print(" Ft "); oled.print(inches); oled.println(" In"); oled.setTextSize(1); oled.println("Place the Deluxe "); oled.println("HeightOmatic at"); oled.println("Base Location, and"); oled.println("Press Go!"); oled.display(); 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; } |