BME280 Temperature 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 accuracy of +-0.50°C which is suitable almost for every design.
Resolution of this sensor is 0.01 °C so you will be reading values such as 25.05°C.
Temperature sensor accuracy
Min temp. [°C] | Max temp. [°C] | Temp. [°C] | Accuracy [°C] | Resolution [°C] |
– | – | 25 | +-0.50 | 0.01 |
0 | 65 | – | +-1.00 | 0.01 |
-20 | 0 | – | +-1.25 | 0.01 |
-40 | -20 | – | +-1.50 | 0.01 |
Wiring
It is crucial to identify what pins on your development board can be used as SCL, SDA
Basic code for testing
/***************************************************************************
Lukas Pomykal 2019
BME280 temperature 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("Temperature = "));
Serial.print(bme.readTemperature());
Serial.println(" *C");
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 temperature 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("Temperature = "));
Serial.print(bme.readTemperature());
Serial.println(" *C");
delay(delayTime);
}