BME280 Pressure measurement

Introduction

This page will take through all steps you need to make this sensor work with your microcontroller such as Arduino, ESP8266, Wemos.
I will be using I2C bus demanding only 4 wires for these pins: Vcc, GND, SCL, SDA.

Typical use

Usually we are looking to use this sensor in a weather monitoring mode.
In a typical indoor use we can achieve absolute +-1.0 hPa and relative accuracy of +-0.12 hPa.
Resolution is 0.01 hPa so you will see a value such as 989.58 hPa.

Pressure sensor accuracy

Min [hPa]Max [ hPa]Min Temp. [°C] Max Temp. [°C] Accuracy [hPa]Resolution [hPa]
3001100065+-1.00.01
7009002540+-0.120.01

Wiring

It is crucial to identify what pins on your development board can be used as SCL, SDA

NodeMcu BME280 wiring
Wemon D1 mini wiring

Basic code for testing

/***************************************************************************
  Lukas Pomykal 2019
  BME280 pressure reading example
  www.lpomykal.cz

  Adafruit library:
  http://www.adafruit.com/products/2651
 ***************************************************************************/

#include <Adafruit_BME280.h>
#define BME280_Address (0x76) // usually (0x76), but might be (0x77)

unsigned long delayTime;

// I prefer I2C bus 
Adafruit_BME280 bme; // BME280 sensor using I2C bus

void setup() {
  Serial.begin(9600);
  Serial.println("BME280 test");

  if (!bme.begin(BME280_Address)) {  // If sensor has not been found (could not been initialized)
    Serial.println("BME280 has not been found!");
    Serial.println("Please check your wiring or BME280_Address");
    while (1);
  }

  delayTime = 1000; // read every second (1000ms = 1s)
}

void loop() {
    Serial.println("BME280:");
    Serial.print(F("Pressure = "));
    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    delay(delayTime);
}

Code with fixed self heating problem

If you want to really use BME280 for some of your projects, please use this code.
BME280 has well known self heating problems causing rising temperature up to + 2°C.

/***************************************************************************
  Lukas Pomykal 2019
  BME280 pressure reading example with advanced settings
  www.lpomykal.cz

  Adafruit library:
  http://www.adafruit.com/products/2651
 ***************************************************************************/

#include <Adafruit_BME280.h>
#define BME280_Address (0x76) // usually (0x76), but might be (0x77)

//It is necessary to read values in a longer interval so the sensor will not heat up itself
//Read every minute (60000 ms = 60 s = 1 min)
const unsigned long delayTime = 60000; 

// I prefer I2C bus 
Adafruit_BME280 bme; // BME280 sensor using I2C bus

void setup() {
  Serial.begin(9600);
  Serial.println("BME280 test");

  if (!bme.begin(BME280_Address)) {  // If sensor has not been found (could not been initialized)
    Serial.println("BME280 has not been found!");
    Serial.println("Please check your wiring or BME280_Address");
    while (1);
  }

  bme.setSampling(Adafruit_BME280::MODE_FORCED, // Force reading after delayTime
                  Adafruit_BME280::SAMPLING_X1, // Temperature sampling set to 1
                  Adafruit_BME280::SAMPLING_X1, // Pressure sampling set to 1
                  Adafruit_BME280::SAMPLING_X1, // Humidity sampling set to 1
                  Adafruit_BME280::FILTER_OFF   // Filter off - immediate 100% step response
                  );
}

void loop() {
    bme.takeForcedMeasurement();
    Serial.println("BME280:");
    Serial.print(F("Pressure = "));
    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    delay(delayTime);
}

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *