Bosch’s BME280 is a precision sensor used in a myriad of applications ranging from weather monitoring to gaming controls to altitude measurement where accuracy of just a few feet is required.

This sensor is simple to use, comes pre-calibrated, and requires no additional components, so you can start measuring relative humidity, temperature, barometric pressure, and altitude in no time. 

So, let’s get acquainted with the BME280, which we have heard a lot about.

BME280 Capabilities

Measuring Temperature

The BME280 can measure temperatures ranging from -40°C to 85°C. Over the temperature range of 0 to 65°C, the accuracy is ±1.0°C; outside of that range, the accuracy drops to ±1.5°C.

Note that this temperature measurement is used internally to calibrate the pressure and humidity sensors. Because the sensor self-heats, the measured temperature is usually slightly higher than the actual temperature. If this is critical to your project, compare the measured temperature to the actual temperature and apply an offset if necessary.

Measuring Humidity

The BME280 can measure relative humidity over a range of 0 to 100% with an accuracy of ±3%.

According to the datasheet, the sensor can measure up to 100% humidity over a temperature range of 0 to 60°C. However, the maximum measurable humidity decreases at extremely high and low temperatures.

Measuring Pressure

The BME280 can measure pressure between 300Pa to 1100 hPa with an absolute accuracy of ±1 hPa.

Over the temperature range of 0 to 65°C, full accuracy is obtained, resulting in an altitude measurement accuracy of approximately ±1 meter. Outside of that range, the accuracy drops to 1.7 hPa.

Calculating Altitude / Elevation

The BME280 can measure pressure with such precision (low altitude noise of 0.25m) that it can also be used as an altimeter with an accuracy of ±1 meter.

Before proceeding, it is important to understand the distinction between Absolute and Relative Altitude. The term “absolute altitude” refers to the height above sea level (MSL), whereas “relative altitude” refers to the height above ground level (AGL).

Note that the BME280 cannot directly measure altitude but can estimate it using pressure readings. Because the BME280 is very good at measuring pressure, it can calculate relative altitude accurately. For example, if you know the altitude of an object sitting on a table and you move it to the floor, the BME280 will show a 2 foot decrease in height.

However, if you’re trying to measure absolute altitude, things become a bit more complicated because the BME280 needs to know the current sea level pressure.

So, to get an accurate absolute altitude measurement, the SEA_LEVEL_PRESSURE constant is provided in the example code below, which you should update with the current sea level pressure at your location.

Hardware Overview

BME280 IC

At the core of the module is the next-generation digital temperature, humidity, and pressure sensor from Bosch – BME280. It is the successor to sensors such as the BMP180, BMP085 and BMP183.

BME280 Chip On The Module

Power

The module includes an on-board LM6206 3.3V regulator and I2C Voltage Level Translator, so you can use it with a 3.3V or 5V logic microcontroller like Arduino without worry.

BME280 Module I2C Voltage Translator & 3.3V Regulator

The BME280 consumes less than 1mA during measurements and only 5μA when idle. Because of its low power consumption, it can be used in battery-powered devices such as handsets, GPS modules, and watches.

I2C Interface

The BME280 module communicates via I2C and supports two I2C addresses, 0x76 and 0x77, allowing up to two sensors to be used on the same bus.

The module’s default I2C address is 0x76HEX, which can be easily changed to 0x77HEX using the provided solder jumper.

BME280 Module I2C Address Selector Solder Jumper

To change the i2c address to 0x77, cut the trace between the middle and left copper pads with a sharp knife. Then, add a solder blob between the middle and right copper pads to short them.

BME280 I2C Address Selection Jumper Setting

Technical Specifications

Here are the specifications:

Input voltage3.3V – 5V
Current consumption1mA (typ.) and 5μA (idle)
Temperature-40°C to 85°C (±1.0°C accuracy)
Humidity0 to 100% RH (±3% accuracy)
Pressure300Pa to 1100 hPa (±1 hPa accuracy)
Altitude0 to 30,000 ft. (±1 m accuracy)

For more information, please refer to the datasheet below.

BME280 Sensor Pinout

The BME280 module has only 4 pins that interface it to the outside world. The connections are as follows:

BME280 Pinout - Temperature Humidity Barometric Pressure Sensor

VIN supplies power to the module. Connect any voltage between 3.3V and 5V to this pin.

GND is the ground pin.

SCL is a serial clock pin for the I2C interface.

SDA is a serial data pin for the I2C interface.

Wiring a BME280 Module to an Arduino

Let’s hook the BME280 module to the Arduino.

Connections are straightforward. Begin by connecting the VCC pin to the Arduino’s 5V output and the GND pin to ground.

Now we are left with the pins that are used for I2C communication. Note that each Arduino Board has different I2C pins that must be connected correctly.  On Arduino boards with the R3 layout, the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. They are also referred to as A5 (SCL) and A4 (SDA).

The following table lists the pin connections:

BME280 ModuleArduino
VCC5V
GNDGND
SCLSCL or A5
SDASDA or A4

The diagram below shows how to connect everything.

Fritzing Wiring BME280 Module to Arduino

Installing Necessary libraries

To begin reading sensor data, you must first install the Adafruit BME280 Library. It is available from the Arduino library manager.

To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the libraries index and update the list of installed libraries.

Arduino Library Installation - Selecting Manage Libraries in Arduino IDE

Filter your search by entering ‘bme280’. Look for the Adafruit BME280 Library by Adafruit. Click on that entry and then choose Install.

Installing BME280 Library In Arduino IDE

The BME280 sensor library makes use of the Adafruit Sensor support backend. So, look for Adafruit Unified Sensor and install it as well (you may have to scroll a bit).

Adafruit Unified Sensor Library Installation

Arduino Example Code

Here is a simple program that reads the temperature, relative humidity, pressure, and approx. altitude from the BME280 module and prints them on the serial monitor.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;

void setup() {
	Serial.begin(9600);

	if (!bme.begin(0x76)) {
		Serial.println("Could not find a valid BME280 sensor, check wiring!");
		while (1);
	}
}

void loop() {
	Serial.print("Temperature = ");
	Serial.print(bme.readTemperature());
	Serial.println("*C");

	Serial.print("Pressure = ");
	Serial.print(bme.readPressure() / 100.0F);
	Serial.println("hPa");

	Serial.print("Approx. Altitude = ");
	Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
	Serial.println("m");

	Serial.print("Humidity = ");
	Serial.print(bme.readHumidity());
	Serial.println("%");

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

You should see a similar output in the serial monitor.

BME280 Temperature Humidity Pressure & Altitude Output On Serail Monitor

Code Explanation:

The sketch begins by including three libraries, namely Wire.h, Adafruit Sensor.h, and Adafruit BME280.h.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

The variable SEALEVELPRESSURE_HPA is then defined. This variable stores the sea level pressure in millibars and is used to calculate absolute altitude for a given pressure by comparing it to the sea level pressure. The default value (1013.25) is used in this sketch, but for accurate results, replace it with the current sea level pressure at your location.

An object of the Adafruit BME280 library is also created so that we can access its functions.

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;

In the setup section of the code, we initialize the serial communication with the PC and call the begin() function.

The begin(I2C_ADDR) function takes the module’s I2C address as a parameter. If you changed the I2C address of your module, you must specify it correctly. This function initializes the I2C interface with the given I2C address and validates the chip ID. It then soft-resets the chip and waits for the sensor to calibrate after wake-up.

Serial.begin(9600);

if (!bme.begin(0x76)) {
	Serial.println("Could not find a valid BME280 sensor, check wiring!");
	while (1);
}

In the loop section of the code, we use the following functions to read temperature, relative humidity, and barometric pressure from the BME280 module.

readTemperature() function returns the temperature.

readPressure() function returns the barometric pressure.

readAltitude(SEALEVELPRESSURE_HPA) function computes the altitude (in meters) by comparing the specified atmospheric pressure (in hPa) to the sea-level pressure (in hPa).

readHumidity() function returns the relative humidity.

Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println("*C");

Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println("hPa");

Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println("m");

Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println("%");

Login
ADS CODE