Example Code for Arduino-Temperature Pressure Altitude Measurement

Last revision 2025/12/16

This article provides a comprehensive guide on using Arduino with the BMP280 sensor to measure temperature, pressure, and altitude. It includes detailed hardware and software preparation instructions, a wiring diagram, and sample code for easy implementation in Arduino IDE.

Hardware Preparation

  • DFRduino UNO (or similar) x 1
  • Gravity: I2C BMP280 Barometer Sensor x1
  • M-M/F-M/F-F Jumper wires

Software Preparation

Wiring Diagram

Arduino_BMP280_Barometer_Sensor_Connection.png

Other Preparation Work

Sample Code

/*!
 * @file bmp280test.ino
 * @brief DFRobot's Temperature & Barometer.
 * @n This example read the Temperature, Barometer and Altitude from BMP280, and then print them
 *
 * @copyright   [DFRobot](https://www.dfrobot.com), 2016
 * @copyright   GNU Lesser General Public License
 *
 * @version  V1.0
 * @date  2016-12-06
 */

#include <Wire.h>
#include "DFRobot_BMP280.h"

DFRobot_BMP280 bmp280;

void setup() {
  Serial.begin(9600);
  Serial.println("BMP280 demo");

  if (!bmp280.begin()) {
    Serial.println("Could not find a valid BMP280 sensor!");
    while (1);
  }
}

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

    Serial.print("Pressure = ");
    Serial.print(bmp280.readPressureValue());
    Serial.println(" Pa");

    Serial.print("Altitude = ");
    Serial.print(bmp280.readAltitudeValue(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");

    Serial.println();
    delay(2000);
}

Result

BMP280_Result.png

Was this article helpful?

TOP