Measure Altitude using BMP280 (I2C interface)

I'm thinking to use pressure sensor for my RC plane so that I can tell how high it fly. Singapore regulation says I cannot fly higher than 60 meter without permit. Although my RC plane at yet to fly 😁, last time I try it fly like a rock, high speed nose dive πŸ˜‚. 60 meters (200 ft) is actualy not that high, I leave in 25th floor and it is around 99 meters based on my Mi Watch 2 altitude meter.

I bought the sensor from AliExpress for SGD $1.37. There are 2 choice, BME or BMP. Both look almos identitcal. The BME is more squarish as show on the picture below. BMP does not have humidity sensor but BMP is cheaper, about 1/3 the price of BME. Anyway I just need the pressure sensor to measure the approximate altitude.

I use the BME280 library by Tyler Glenn. Why? No reason, it just happen to be on the top list when I search at library manager. I'm sure the other library will also work.

Schematic from the seller site:

The Arduino nano connection to the BMP280 is as below


The experiment code below is to read temperature and pressure from the module and then calculate approximate altitude. You need to google for the sea level pressure of  your area. I got mine from here πŸ˜‰. Also I'm using my smart watch (Mi Watch 2) to calibrate the data. I assume Mi Watch 2 pressure sensor is calibrated 😬

        #include <BME280I2C.h>
    #include <Wire.h>

    #define sealevel (1007.8)   // Singapore sea level pressure

    BME280I2C bme;

    void setup()
    {
      Serial.begin(9600);
      Wire.begin();

      while(!bme.begin())
      {
        Serial.println("Could not find BME280 sensor!");
        delay(1000);
      }
    }

    void loop()
    {
      float temp(NAN), hum(NAN), pres(NAN);

      BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
      BME280::PresUnit presUnit(BME280::PresUnit_Pa);

      bme.read(pres, temp, hum, tempUnit, presUnit);

      Serial.print("Temp: ");
      Serial.print(temp);
      Serial.println(" Β°C");
   
      Serial.print("Pressure: ");
      Serial.print(pres-200);     // Offset by 200 based on Mi Watch 2 pressure sensor
      Serial.println(" Pa");

      float atmospheric = (pres-200) / 100;     // Convert Pa to hPa
      float alt =  44330.0 * (1.0 - pow(atmospheric / sealevel, 0.1903));
 
      Serial.print("Approx. Altitude = ");
      Serial.print(alt);
      Serial.println(" m");
      Serial.println();

      delay(1000);
    }

This is what it's look like from the serial monitor:



Comments

Popular posts from this blog

Building RC Plane Under 250 grams (Part 1)

Arduino Nano clone (fake FT232RL)

A2212/5T 2450KV