Language: EN

medir-temperatura-y-presion-barometrica-con-arduino-y-bmp280

Measuring temperature and barometric pressure with Arduino and BMP280

What is a BMP280?

The BMP280 is a digital thermometer and barometer from the manufacturer Bosch Sensortech, which allows readings of temperature, atmospheric pressure, and estimation of altitude above sea level.

The BMP280 is a more accurate replacement for the previous BMP180 and BMP085, with lower power consumption and smaller size, while maintaining its low cost, even lower than the previous models.

The measurement ranges are maintained with respect to the BMP180 and the precisions are also maintained with respect to the BMP180. For temperature, the range is from -40º to 85ºC, with a precision of ±1.0C.

For atmospheric pressure / altimeter, it ranges from 300hPa to 1110 hPa, equivalent to an altitude of -500m to 9000m above sea level. With an absolute precision of ±1.0C and 1.0 hPa, and the relative precision of 0.12 hPa, equivalent to an altitude precision of approximately ±1m.

On the other hand, the measurement resolution improves substantially, going to 0.01ºC (from 0.1ºC in the BMP180) in temperature measurements, and 0.16 Pa (from 1 Pa in the BMP180).

Furthermore, the BMP280 is 63% smaller than the BMP180. Consumption also improves, going from 12 µA to 2.7 µA for measurements at 1Hz.

The BMP280 incorporates I2C and SPI communication, making it very simple to connect to a processor like Arduino. In comparison, the previous model only had I2C.

The supply voltage is 1.8 to 3.6V, and it is possible to find it in both 3V3 and 5V modules, which incorporate the necessary level adaptation.

Price

The BMP280 is a fairly inexpensive sensor, considering that it has temperature, humidity, and pressure measurement in the same device. The price is usually lower in the 3V3 modules, compared to those that allow both 3V3/5V.

arduino-bmp280-bme280-componente

A compatible 3V3/5V BMP280 can be found for about €1.20, from international sellers on eBay or AliExpress.

Physically, the BMP280 is identical to the BME280 that we saw in this post. The BME280 incorporates humidity measurement, but in exchange has a higher price.

Wiring diagram

The connection is simple, we simply power the module from Arduino using GND and 5V and connect the SDA and SCL pins of Arduino to the corresponding pins of the BMP280.

arduino-bmp280-bme280-esquema

While the connection seen from the Arduino side would look like this.

arduino-bmp280-bme280-conexion

The bus direction changes depending on the logic state of the SDO pin, and if left disconnected the direction remains undetermined, so it may appear that it is not working correctly.

SDOI2C Address
GND0x76
3V30x77

On Arduino Uno, Nano, and Mini Pro, SDA is pin A4 and SCK is pin A5. For other Arduino models, consult the corresponding pinout diagram.

Verify that your board is compatible with 5V before connecting it to Arduino. If not, you will need to use a logic level adapter.

Code examples

To read the BMP280, we will use the library developed by Adafruit, available at https://github.com/adafruit/Adafruit_BMP280_Library.

In the library developed by Adafruit, the I2C bus uses the default address (0x77), to modify it you have to edit the file “Adafruit_BMP280.h” and in line 37 #define BMP280_ADDRESS (0x77) change the address (0x76).

The library provides code examples, which it is advisable to review. The following examples, for example, are modifications based on those available in the library.

Obtain the values of temperature, humidity, and pressure

In this example, the measurement of the raw values of temperature, humidity, and pressure is obtained, and they are displayed on the screen. These values are useful, for example, for making a weather station.

Adafruit_BMP280 bmp;

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,     /* 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.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));
    Serial.println(" m");

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

Download the code

All the code from this post is available for download on Github. github-full