Arduino Projects

Interface BME280 Temperature, Humidity & Pressure Sensor with Arduino

Give your next Arduino project the ability to sense the world around it with BME280. These sensors are fairly simple to use, pre-calibrated and don’t require extra components so you can start measuring relative humidity, temperature, barometric pressure & approx. altitude in no time.

BME280 Temperature, Humidity and Pressure Sensor

At the heart of the module is the next-generation digital temperature, humidity and pressure sensor manufactured by Bosch – BME280. It’s a successor to sensors like BMP180, BMP085 or BMP183.

BME280 Chip On The Module

This precision sensor can measure relative humidity from 0 to 100% with ±3% accuracy, barometric pressure from 300Pa to 1100 hPa with ±1 hPa absolute accuracy, and temperature from -40°C to 85°C with ±1.0°C accuracy.

The pressure measurements are so precise (low altitude noise of 0.25m), you can even use it as an altimeter with ±1 meter accuracy.

BME280 Sensing Range
Temperature -40°C to 85°C (±1.0°C accuracy)
Humidity 0 to 100% RH (±3% accuracy)
Pressure 300hPa to 1100hPa (±1hPa accuraccy)
Altitude 0 to 30,000ft (±1 meter accuracy)

For more details, please refer below datasheet.

Power Requirement

The module comes with 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 during idle. This low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches.

I2C Interface

The module features a simple two-wire I2C interface which can be easily interfaced with any microcontroller of your choice.

The default I2C address of the BME280 module is 0x76HEX and can be changed to 0x77HEX easily with the solder jumper besides chip.

BME280 Module I2C Address Selector Solder Jumper

Procedure to Change I2C Address

  • Locate the solder jumper besides chip. By default the middle copper pad is connected to the left pad.
  • Scratch the connection between the middle and the left copper pad to disconnect those using a sharp knife.
  • Add a solder blob between the middle and the right copper pad to join them. It allows you to set the I2C address 0x77HEX.

BME280 I2C Address Selection Jumper Setting

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 is the power supply for the module which can be anywhere between 3.3V to 5V.

GND should be connected to the ground of Arduino

SCL is a serial clock pin for I2C interface.

SDA is a serial data pin for I2C interface.

Wiring BME280 Module to Arduino UNO

Let’s hook the BME280 module up to the Arduino.

Connections are fairly simple. Start by connecting VIN pin to the 5V output on the Arduino and connect GND to ground.

Now we are remaining with the pins that are used for I2C communication. Note that each Arduino Board has different I2C pins which should be connected accordingly. On the 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 known as A5 (SCL) and A4 (SDA).

If you have a Mega, the pins are different! You’ll want to use digital 21 (SCL) and 20 (SDA). Refer below table for quick understanding.

I2C Pin Configration of Arduino Uno,Arduino Nano and Arduino Mega
SCL SDA
Arduino Uno A5 A4
Arduino Nano A5 A4
Arduino Mega 21 20
Leonardo/Micro 3 2

The following diagram shows you how to wire everything.

Fritzing Wiring BME280 Module to Arduino
Wiring BME280 Module to Arduino

Installing Necessary libraries

Communicating with a BME280 module is a bunch of work. Fortunately, Adafruit BME280 Library was written to hide away all the complexities so that we can issue simple commands to read the temperature, relative humidity & barometric pressure data.

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

Arduino Library Installation - Selecting Manage Libraries in Arduino IDE

Filter your search by typing ‘bme280’. There should be a couple entries. Look for Adafruit BME280 Library by Adafruit. Click on that entry, and then select Install.

Installing BME280 Library In Arduino IDE

The BME280 sensor library uses the Adafruit Sensor support backend. So, search the library manager for Adafruit Unified Sensor and install that too (you may have to scroll a bit)

Adafruit Unified Sensor Library Installation

Arduino Code – Reading Temperature, Relative Humidity & Barometric Pressure

The following sketch will give you complete understanding on how to read temperature, relative humidity & barometric pressure from BME280 module and can serve as the basis for more practical experiments and projects.

#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);
}

Here’s how the output looks like in the serial monitor.

BME280 Temperature Humidity Pressure & Altitude Output On Serail Monitor

Code Explanation:

The sketch starts with including four libraries viz. Wire.h, SPI.h, Adafruit_Sensor.h and Adafruit_BME280.h.

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

Next, we define SEALEVELPRESSURE_HPA variable needed to calculate the altitude and create an object of Adafruit_BME280 library so that we can access functions related to it.

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;

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

The begin(I2C_ADDR) function takes the I2C address of the module as parameter. If your module has different I2C address or you changed it, you need to specify it correctly. This function initializes I2C interface with given I2C Address and checks if the chip ID is correct. It then resets the chip using soft-reset & waits for the sensor for calibration after wake-up.

Serial.begin(9600);

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

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

readTemperature() function returns the temperature from the sensor.

readPressure() function returns the barometric pressure from the sensor.

readAltitude(SEALEVELPRESSURE_HPA) function calculates the altitude (in meters) from the specified atmospheric pressure (in hPa), and sea-level pressure (in hPa).

readHumidity() function returns the relative humidity from the sensor.

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("%");