Learn how to measure temperature, barometric pressure, and altitude using the BMP280 sensor with Arduino.
The BMP280 is a digital sensor by Bosch Sensortech that measures temperature, barometric pressure, and altitude. It is an improved version of the BMP180 with better accuracy, power efficiency, and smaller size.
Connect the BMP280 sensor as follows:
Use the Adafruit BMP280 library to get temperature, pressure, and altitude readings. Install the library from Adafruit's GitHub repository.
#include
Adafruit_BMP280 bmp; // Create BMP280 object
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
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.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Altitude = "));
Serial.print(bmp.readAltitude(1013.25)); // Adjust sea-level pressure as necessary
Serial.println(" m");
Serial.println();
delay(2000);
}