Interface the BMP280 Barometric Pressure and Altitude Sensor with Arduino

What is a BMP280 sensor?

The BMP180 is a digital Barometric pressure and Altitude sensor that is used to measure the atmospheric pressure and altitude of any place. It is very small and feasible which makes it easier to use it in battery-powered devices like mobile phones, GPS-based smartwatches, and weather stations. It is based on the piezo-resistive pressure sensor technology due to which it offers higher accuracy, linearity, stability, and EMC robustness. In order to achieve higher accuracy, it uses a temperature sensor that is present inside the BMP180 sensor. So, you can use it as a temperature measuring sensor also. The accuracy of measuring pressure is ±1 hPa and for temperature, it is ±1 °C. You can easily interface it with any microcontroller using both I2C and SPI. 

Pin Diagram of the BMP280 Barometric Pressure and Altitude Sensor

BMP280 Sensor pinout

Pin Uses of the BMP280 Sensor

  • The VCC pin is used to connect 5V.
  • The GND pin is used to connect GND.
  • The SCL pin is a serial clock pin. You have to connect this pin to the SCL pin of Arduino UNO.
  • The SDA pin is a serial data pin. You have to connect this pin to the SDA pin of the Arduino UNO
  • The CSB pin is a chip select pin. You have to connect this pin to the GND.
  • The SDO pin is a Serial Data Out pin. You have to connect this pin to 5V.

Features of the BMP280 Barometric Pressure and Altitude Sensor

  • The operating voltage is 1.7-3.6V DC.
  • The current consumption is 3.4uA.
  • The operating range for pressure is 300-1100hPa.
  • The operating range for temperature is -40°C – 80°C.
  • The accuracy for absolute pressure is ±1hPa.
  • The accuracy for relative pressure is ±0.12hPa
  • You can interface it using I2C and SPI.

Components needed for interfacing 

  • Arduino UNO
  • BMP280 sensor
  • Breadboard
  • Jumper wires

Pin connection of the BMP280 Barometric Pressure and Altitude Sensor with Arduino UNO

  • Connect the VCC pin of the sensor to the 5V pin of the Arduino UNO.
  • Connect the GND pin of the sensor to the GND pin of the Arduino UNO.
  • Connect the SCL pin of the sensor to the A5 pin of the Arduino UNO.
  • Connect the SDA pin of the sensor to the A4 pin of the Arduino UNO.
  • Connect the SDO pin of the sensor to the GND pin of the Arduino UNO.
  • Connect the CBS pin of the sensor to the 5V pin of the Arduino UNO.

Circuit diagram of the BMP280 Barometric Pressure and Altitude Sensor with Arduino UNO

BMP280 sensor Arduino circuit

Before writing and uploading the code to the Arduino UNO board, you have to download this BMP280 sensor library first and then install it in the Arduino IDE. Link to the BMP180 sensor library: https://github.com/mahfuz195/BMP280-arduino-library

Arduino code for the BMP280 Barometric Pressure and Altitude Sensor

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

Adafruit_BMP280 bmp; 
Adafruit_Sensor *bmpTemp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmpPressure = bmp.getPressureSensor();

void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
    Serial.println(F("Problem with wiring"));
    while (1) delay(10);
  }

  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     
                  Adafruit_BMP280::SAMPLING_X2,     
                  Adafruit_BMP280::SAMPLING_X16,    
                  Adafruit_BMP280::FILTER_X16,      
                  Adafruit_BMP280::STANDBY_MS_500); 
  bmpTemp->printSensorDetails();
}

void loop() {
  sensors_event_t tempEvent, pressureEvent;
  bmpTemp->getEvent(&tempEvent);
  bmpPressure->getEvent(&pressureEvent);
  
  Serial.print(F("Temperature:"));
  Serial.print(tempEvent.temperature);
  Serial.println(" *C");

  Serial.print(F("Pressure:"));
  Serial.print(pressureEvent.pressure);
  Serial.println(" hPa");

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

Working of code

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

Include all the necessary Libraries used by this sensor. The wire.h library is for I2C communication. The SPI.h library is for SPI communication. The Adafruit_BMP280.h library is for the BMP280 sensor.

Adafruit_BMP280 bmp; 
Adafruit_Sensor *bmpTemp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmpPressure = bmp.getPressureSensor();

Create one object named bmp of type Adafruit_BMP280, you can give any name to it. We will use this object to access all the functions of the Adafruit_BMP280 library. Create one pointer named bmpTemp, we will use to get the temperature data from the sensor. Create another pointer named bmpPressure, we will use it to get pressure data from the sensor.

void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
    Serial.println(F("Problem with wiring"));
    while (1) delay(10);
  }

In the void setup() function, initiate serial communication with the baud rate of 9600. Then in if statement initiate BMP sensor using bmp.begin() function. If sensor is not initiated, you will get an error.

bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     
                  Adafruit_BMP280::SAMPLING_X2,     
                  Adafruit_BMP280::SAMPLING_X16,    
                  Adafruit_BMP280::FILTER_X16,      
                  Adafruit_BMP280::STANDBY_MS_500); 
  bmpTemp->printSensorDetails();
}

Set all the necessary parameters of the sensor. You will all this information from the data sheet of this sensor. The first parameter is for setting the operating mode. The second parameter is for setting oversampling rate for temperature measurement. The third parameter is for setting oversampling rate for pressure measurement. The fourth parameter is for filtering and the last parameter is for setting standby time.

void loop() {
  sensors_event_t temp_event, pressure_event;
  bmpTemp->getEvent(&temp_event);
  bmpPressure->getEvent(&pressure_event);

In the void loop() function, we have first created two variable of type sensors_event_t. We will use them to create two events so that we can access temperature and pressure data from the sensor.

Serial.print(F("Temperature:"));
  Serial.print(tempEvent.temperature);
  Serial.println(" *C");

  Serial.print(F("Pressure:"));
  Serial.print(pressureEvent.pressure);
  Serial.println(" hPa");

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

In the last, print the temperature and pressure dat on the serial monitor.

Leave a Reply