
In many of our previous articles, we have used many different types of temperature and humidity sensors like DHT22, DHT11, DS18b20, and LM35 to measure environmental parameters. In every one of those articles, the one thing in common is that none of those sensors measure barometric pressure. So in today's article, we wanted to interface the BMP280 with an Arduino and measure barometric pressure.
BMP280 Pressure Sensor with Arduino - Quick Overview
Build Time: 2-3 hours | Cost: $10-20 | Difficulty: Beginner
What You'll Learn: I2C communication, Adafruit BMP280 library, Barometric pressure measurement, Altitude calculation
Applications: Weather station, Altitude monitoring, Environmental sensing, IoT weather systems
Table of Contents
BMP280 Sensor Module
Why BMP280, you ask? Because this sensor costs low and it only provides both temperature and barometer readings, and as pressure changes with altitude, we can also use it as an altimeter with ±1 meter accuracy. But if you want to get all the weather data in one package, there exists another sensor named BME280 that provides Temperature, Humidity, Barometric Pressure, and Altitude, but as you can probably imagine, it comes with a high cost.
Working
Let's understand how the BMP280 sensor works. At its core, it has a tiny flexible membrane inside that bends when air pressure changes. You can think of it as a microscopic eardrum. It also measures temperature because electronic components get cranky with temperature changes, so it uses that reading to keep the pressure data accurate. Since air pressure drops as you go higher, the sensor can calculate altitude too. All the complex math stuff happens inside the chip, so your Arduino just gets clean digital data over I2C.
Pinout
The BMP280 Digital Pressure Sensor module has 6 pins: VCC, GND, SCL, SDA, CSB, and SDO. All the pins of this sensor module are digital, except VCC and Ground. The Pinout of the BMP280 barometric Pressure and Temperature Sensor is shown below:
VCC is the power supply pin of the BMP280 that can be connected to 3.3V or 5V of the supply. But note that the analog output will vary depending on the provided supply voltage.
Ground is the ground pin of the Sensor, and it should be connected to the ground pin of the Arduino.
SCL stands for Serial Clock. The master device pulses this pin at a regular interval to generate a clock signal for communication.
SDA stands for Serial Data. Through this pin, data exchange happens between two devices.
CSB is the chip select pin of the module. If you are communicating with the device with SPI, you can use this pin to communicate to select one of multiple devices connected to the same bus.
SDO is the Serial Data Out pin of the module. An output signal on a device where data is sent out to another SPI device.
Parts and Components
The manufacturer made this sensor so that anybody with basic knowledge in electronics can work with this sensor, so the module only requires very few readily available parts, like a few resistors and two filter capacitors for stable operation. This is a MEMS-based sensor and can detect sudden changes in barometric pressure and temperature. The parts marking of the sensor is shown below.
This sensor has six pins altogether, among which two are power pins, which are VCC and GND. And the other four pins are for data and clock signals, which are 5V-tolerant. As you can see in the above image, this board has two filter capacitors, both of which are 100nF capacitors. One capacitor is used to filter the analog power line, and another one is used to power the digital power line. Other than that, we have three pull-up resistors and a pull-down resistor for SCL, SDA, SDO, and SDI, respectively. With all these parts, the BMP280 sensor is made.
Schematic Diagram
The circuit diagram of the BMP280 Temperature and Pressure Sensor is shown below, and as you can see, it's very simple to understand.
The BMP280 has two separate power supply pins: VDD is the main power supply for all internal analog and digital functional blocks, and VDDIO is a separate power supply pin, used for the supply of the digital interface. For those two pins, two 100nF decoupling capacitors are used to filter the DC power supply line. Other than that, the SCL, SDA, and the CSB line need to be pulled up with a 10K resistor according to the datasheet of the device. On the other hand, the SDO line needs to be pulled down for this sensor to work properly.
Comparison with BME280
If you search for weather sensors on the internet, you will come across some affordable sensors. Among those, there are two popular sensors, namely the BMP280 and the BME280. The name of the two modules sounds pretty similar, but there are some key differences, and in this section of the article, we will discuss those.
The major difference between the BME280 and the BMP280 sensor is that the BME280 sensor can measure humidity, while the BMP280 cannot measure humidity. Other than that, there is not much difference between the two devices, and most parameters of the sensor remain the same.
FAQ
Can BMP280 measure Altitude?
This sensor can measure barometric pressure and temperature with very good accuracy. Because pressure changes with altitude, we can also use it as an altimeter with ±1 meter accuracy!
What is the use of BMP280?
The BMP280 sensor is used to find the Digital Pressure and Temperature, whereas the BME280 can be used to measure digital pressure, temperature, and altitude.
Can BMP280 measure humidity?
The BMP280 can only measure temperature and air pressure, while the BME280 can measure humidity in addition to temperature and air pressure.
What is the temperature range of the BMP280 sensor in which it remains operational?
The temperature range and the operating range of this sensor are exactly the same: -40 … +85 °C. That means the temperature of the sensor should be within that range for stable operation.
Interfacing BMP280 with Arduino
Wiring Diagram
Now that we completely understand how the BMP280 sensor works, let’s look at the BMP280 Arduino connection by wiring all the required pins to the Arduino UNO board.
In the above figure, the wiring diagram of the BMP280 sensor with Arduino is shown we are using the I2C bus to connect the sensor to the Arduino for that we have connected the power pins of the Arduino board to the power pins of the BMP280 module and we have connected the SCL and SDA pins of the module to the SCL and SDA pin of the Arduino board.
The practical test hardware is shown below.
Code Implementation
The code for interfacing the BMP280 Sensor to Arduino is shown below. The code is very simple and easy to understand because we are using the Adafruit BMP280 library, which makes the coding process very easy. So before we start the coding process, we need to install the library. To do that, go to the Manage Library section of the Arduino and search for BMP280. You will get the Adafruit BMP280 library. Click install, and you will be prompted to install all the dependencies. Click on the Install all button, and the library should get installed.
Now we can start our coding process. We initialize our code by declaring all the required libraries, and we also make an instance of the Adafruit_BMP280 class. We also define the address of the module in a macro named BMP280_ADDRESS.
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#define BMP280_ADDRESS 0x76
Adafruit_BMP280 bmp; // I2C
Next, we have our setup() function. In the setup function, as always, we initialize the serial for debugging. We also defined a status variable to check if the begin method of the BMP instance was able to communicate with the module or not. If the communication process returns unsuccessful, we print some debug message on the serial monitor window; otherwise, we continue with the setup.
void setup() {
Serial.begin(9600);
while ( !Serial ) delay(100); // wait for native usb
Serial.println(F("BMP280 test"));
unsigned status;
status = bmp.begin(BMP280_ADDRESS);
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
If the communication process with the module returns a successful message, we set up the important parameters of the library, which are Operating Mode, Temperature Oversampling, Pressure oversampling, Filtering, and Standby time. And with that, we finish our setup function.
/* Default settings from the datasheet. */
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. */
}
Next, we have our loop function. In the loop function, we just call the readTemperature(), readPressure(), and readAltitude(1013.25) instances of the bmp class and print the data onto the serial monitor window. And that marks the end of our code portion.
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("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
Serial.println(" m");
Serial.println();
delay(2000);
}
Working Demonstration
The GIF below shows the BMP280 Temperature and Pressure sensor in working condition. We are demonstrating the working of this sensor with temperature because we cannot change the surrounding pressure, so we made a simple setup to show you that the sensor is working properly.
Troubleshooting
- The most common problem for BMP280 sensors is: Could not find a valid BMP280 sensor, check wiring!, If you are having this issue, it might be that you're not using the correct I2C address. The sensor address of the BMP280 is (0x76). You need to define that in the code for proper operation, or you can use the I2C Scanner sketch to find the sensor address.
- Check if the VCC and the ground of the sensor are connected to the VCC and ground of the Arduino.
- Check if the SCL is connected to the A5 pin and SDA is connected to the SDA pin on the Arduino Board.
- Check your breadboard and jumper wires; if the jumper wires get damaged, that can sometimes cause problems.
GitHub Repository
More Sensor Interfacing Projects
Broaden your Arduino expertise by exploring other popular temperature and humidity sensors. These tutorials cover the DHT22, DS18B20, and LM35 modules, providing step-by-step wiring instructions, code examples, and practical tips to help you create versatile environmental monitoring projects.
DHT22 Temperature and Humidity Sensor with Arduino
In this tutorial, you will learn about the DHT22 Temperature and Humidity Sensor Module and how to interface it with Arduino Uno.
Arduino DS18B20 Sensor Project
Learn the DS18B20 Temperature Sensor pinout, working principle, and how to interface it with Arduino. This tutorial includes complete code, circuit diagram, and step-by-step guidance.
Arduino LM35 Temperature Sensor Interfacing
This tutorial explains how to wire the LM35 Temperature Sensor with Arduino and output temperature readings to the serial monitor.
Complete Project Code
/***************************************************************************
This is a library for the BMP280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BMP280 Breakout
----> http://www.adafruit.com/products/2651
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#define BMP280_ADDRESS 0x76
Adafruit_BMP280 bmp; // I2C
void setup() {
Serial.begin(9600);
while ( !Serial ) delay(100); // wait for native usb
Serial.println(F("BMP280 test"));
unsigned status;
status = bmp.begin(BMP280_ADDRESS);
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
/* Default settings from datasheet. */
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("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
Serial.println(" m");
Serial.println();
delay(2000);
}
Your wiring is i2c, you did not introduce spi wiring to uno