How to Hookup BME280 Sensor to Arduino using I2C

Overview

The BME280 from Bosch Sensortec is a integrated environmental sensor designed for the mobile market. It a low power consumption design that combines high linearity and high accuracy sensors for pressure, humidity and temperature.

The BME280 supports either SPI or I2C interface to communicate with the micro controller.

Because of the small size of the sensor, the best way to use this sensor is with a breakout board. The Adafruit breakout board is used here.

In this hookup we are only connecting one device to the Arduino using the I2C bus. We can use either address (0x77 or 0x76). It reads the barometric pressure, humidity and temperature and displays it on the console.

Images

Bosch BME280 Sensor on Adafruit Breakout board
Note: Images shown on this page are not to scale.

Hardware and Software Parts List


Data Sheets


Wiring up the BME280 Sensor

We can wire up the sensor using either the SPI or I2C bus. The SPI bus requires 4 wires plus power and ground. The I2C bus only requires 2 wires plus power and ground. Both can be wired using 5V or 3.3V as the power source as the breakout board has a power regulator on board to regulate it to 3.3V for the sensor.

Hookup Diagram for Adafruit BME280 breakout board to Arduino using SPI

For hookup details using the SPI bus (including sketch and library) click on this link.

Hookup BME280 using SPI bus

Hookup Diagram for Adafruit BME280 breakout board using I2C and Default Address (0x77)


If we use the I2C bus the sensor can use one of two addresses to communicate with. The default is 0x77. The address is set by the voltage applied to the SDO pin. The Adafruit board has a pullup resistor on the breakout board which will pull the pin high and set the default address to 0x77. The alternative is pull the pin to ground and this will set the address to 0x76.

With the I2C bus we only need to connect the following:

  • Analog Pin 5 to SCK
  • Analog Pin 4 to SDI
Hookup Arduino to Bosch BME280 Sensor I2C

Hookup Diagram for Adafruit BME280 breakout board using I2C and Alternative Address (0x76)

To enable the alternative address we need to connect the SDO pin to ground. In the software when we create the BME280 object we need to define the address. If no address is specified the default 0x77 will be used.

With the I2C bus we only need to connect the following:

  • Analog Pin 5 to SCK
  • Analog Pin 4 to SDI
  • SDO to Ground
Hookup Arduino Bosch BME280 Sensor using I2C address 0x76

Software

The hookup and Arduino Sketch is for connecting a single Adafruit BME280 breakout board using either address 0x77 or 0x76.

You will need to download the cactus.io BME280_I2C library to work with this sample sketch. The library supports reading the barometric pressure, humidity and temperature from the sensor.

To get the data from the sensor we need to call bme.readSensor(). We can then call the various functions to get the temperature, humidity and pressure.

The sensor returns the temperature in degrees celsius by design. We can call the method in the BME280 library called getTemperature_C to get the celsius value or getTemperature_F for the value in fahrenheit.

The barometric pressure from the sensor is returned in Pascals. 100 Pascals = 1hPa = 1 millibar. The library method getPressure_P will return the value in Pascals. The method getPressure_MB will return the value in millibars.

When we create the BME280 object in the sketch we can use the default which is BME280_I2C bme which will create an object using the default 0x77 address. To create an object using the alternative address (0x76) we need to declare it as BME280_I2C bme(0x76).

We have found that when the BME280 is enclosed inside a case or nearby a circuit board the heat generated by voltage regulators can affect the temperature reading from the BME280. We have included a function in the library that allows us to apply a temperature calibration offset to the value returned by getTemperature_C or _F. Basically it justs adds the calibration offset. So if the temperature is reading 2 degrees high then we use this function:

bme.setTempCal(-2);   which will subtract 2 degrees from the temperture reading.

The default calibration offset is 0. So you only have to use this function if you want to apply a calibration value other than 0.

Limitations
  • The sketch Supports only I2C bus connection.
  • The sketch Supports only one sensor connected.
  • Its blocking code.

Library

The cactus_io_BME280_I2C library provides the following functions:

  • BME280_I2C() Creates an object using default address of 0x77
  • or BME280_I2C(int address) Creates an object using alternative address. For example BME280_I2C(0x76)
  • begin() Called to initialise the sensor after the object is created
  • setTempCal(float) Allows you to define a temp calibration offset if it reads high
  • readSensor() Called to read data from the sensor
  • getTemperature_C() Returns a float value in degrees celsius
  • getTemperature_F() Returns a float value in degrees fahrenheit
  • getHumidity() Returns a float as a percentage humidity
  • getPressure_MB() Returns a float in millibars
  • getPressure_HP() Returns a float in hectapascals

Sample Sketch

Bosch BME280 I2C Sample Sketch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <Wire.h>
#include "cactus_io_BME280_I2C.h"

// Create BME280 object
BME280_I2C bme; // I2C using address 0x77
// or BME280_I2C bme(0x76); // I2C using address 0x76

void setup() {

Serial.begin(9600);
Serial.println("Bosch BME280 Pressure - Humidity - Temp Sensor | cactus.io");

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

bme.setTempCal(-1);// Temp was reading high so subtract 1 degree

Serial.println("Pressure\tHumdity\t\tTemp\ttTemp");
}

void loop() {

bme.readSensor();

Serial.print(bme.getPressure_MB()); Serial.print(" mb\t"); // Pressure in millibars
Serial.print(bme.getHumidity()); Serial.print(" %\t\t");
Serial.print(bme.getTemperature_C()); Serial.print(" *C\t");
Serial.print(bme.getTemperature_F()); Serial.println(" *F");

// Add a 2 second delay.
delay(2000); //just here to slow down the output.
}

Sketch Console Output

Arduino Bosch BME280 Barometric Pressure Sensor Sketch

Other Resources

Adafruit BME280 Barometric Pressure Tutorial


License