Skip to content

Altimeter Decryption

The barometer is the core sensor for drone altitude hold functionality. In this project, you will learn how to read barometer data, calculate real altitude, and implement more precise altitude hold.

  • Barometer working principles
  • Altitude calculation methods
  • Data filtering techniques
  • Dead zone control
Item Quantity Notes
ESP32 Drone 1 Fully assembled
BMP280 Barometer Module 1 Measures pressure and altitude
Serial Debug Assistant 1 serial_debug.exe

Connect BMP280 to ESP32:

BMP280 ESP32
VCC 3.3V
GND GND
SCL GPIO 22
SDA GPIO 21

Extract barometer.zip and open with VS Code.

Open sensors_bmp280.c and find the bmp280_init function:

void bmp280_init(void) {
// ... initialization code ...
p0 = 101325; // Sea level pressure (Pa)
}

Check local current pressure using a weather app (e.g., 100800 Pa) and modify p0:

p0 = 100800; // Local current pressure

Compile and flash the code, open the serial debug assistant, and observe the data:

  • When stationary, pressure values should be stable
  • When moving the drone up and down, altitude values should change accordingly

Open altitude_hold.c and add “altitude hold dead zone”:

if (fabs(current_altitude - target_altitude) < 0.1) {
// Altitude difference less than 0.1 meters, no adjustment
return;
}

Set target altitude to 1 meter and observe if the drone can maintain stable altitude.

  • Add low-pass filter
  • Check sensor connections
  • Calibrate local pressure value
  • Check temperature compensation

Congratulations! You have mastered the use of the barometer and implemented precise altitude hold functionality!

In the next project, you will learn how to read IMU data and calculate drone attitude using complementary filtering algorithm.

First published atdrone.imagrove.com/intermediate/altimeter/Please credit Imagrove and link back to this page when quoting or republishing.

Questions or issues with this tutorial?

Sign in with GitHub to leave a comment. If a step fails for you, tell us — we verify it and update the tutorial.

ImagroveMore ESP32 tutorials · ESP32 IoT Tutorial

© 2026 ESP32 Drone. All rights reserved.