How To use the Kalman filter with the BMP280?

Hello ...
I recently started to use the BMP280 for measuring pressure Temp and ALTITUDE. The main goal is to measure altitude. I can measure altitude with the example sketch with the BMP280 libary. But it is not accurate and has noise interruption. I have seen people use the "Kalman" filter with sensors like the BMP280. I also am using the MPU6050 if that is necessary to calculate Altitude. If anyone would like to get back to me that would be very helpful.


bmp280test.ino (2.0 KB)

Regards :smiley:

For a one dimensional measurement like pressure or altitude, simple averaging of N measurements, or an exponential moving average filter is all you need.

The 1D Kalman filter is equivalent to an exponential filter average.

Hi, @sszabo
To add code please click this link;

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Kalman Filter Lib:

Thanks for the replies, I'm sorry, I am pretty new to the forum. Anyway I have seen kalman library but I don't know how to implement that into the BMP280 sketch.

  This is a library for the BMP280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BMP280 Breakout

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK  (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS   (10)

Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

void setup() {
  Serial.println(F("BMP280 test"));

  //if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
                      "try a different address!"));
    while (1) delay(10);

  /* Default settings from datasheet. */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

void loop() {
    Serial.print(F("Temperature = "));
    Serial.println(" *C");

    Serial.print(F("Pressure = "));
    Serial.println(" Pa");

    Serial.print(F("Approx altitude = "));
    Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
    Serial.println(" m");


Thakyou ...

No need to bother. You really can't do much better than adding up (for example) 100 measurements and dividing by 100. There is absolutely no advantage to using a Kalman filter for such a simple task.

If you are learning to program, start simply and work your way up!

what can i do??
:thinking: :grinning:

I verify the code of kalman.cpp and it comes up with the error "'Kalman' does not name a type; did you mean 'Kalman_h'?"

Any solutions?
Thanks in advance

I've not used the Kalman filter but I know the folks who have answered and I very sure they are correct.

An important question; how often are your reading the BMP and how fast do you need to have filtered data?
For instance, measuring altitude of a model rocket will have different needs than measuring altitude for a dirt biker.

Another Hint. If your drive to use the Kalman filter is because your not good at coding and don't know where to start a simple averaging filter. That is a different question. You should start a new thread or at least state your current situation.

Ok thanks @JohnRob I am pretty good at programming but I get confused about certain things. I should probably start slower but I’ll do some research.

Every 500 milliseconds I want to log dyne data.

OK that's fine but do you know how fast you can measure the BMP-280? Can you disable the temperature and humidity measurement to speed up the repetition rate of the Pressure sensor portion?

Its been a long time but I seem to recall 1/2 second is near the max measurement rate for this sensor. If this is true, will not be able to filter your data.

I think this may answer your need:

Hi @mrburnette haven’t seen you around here for a while.

Welcome back !

Hi, LarryD...
Off in Raspberry land and STM32duino world... think maybe 3 or 4 years! Spent the last 6 mo. with C on a TI CC2533 just to get back into thinking low-level. Sometimes I just feel the need to be "grounded" :wink:

Thanks I’ll do some research and get back to you.