BME280 Humidity 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 +-3% RH (Relative Humidity) which is sufficient for almost every use.
Resolution is 0.01% so you will see a value such as 57.42 %RH

Humidity sensor accuracy

Min [%RH]Max [%RH]Temp. [°C]Accuracy [%RH ]Resolutio [%RH ]
208025+-30.01
Min [hPa]Max [hPa] Min temp. [°C]Max temp. [°C]Accuracy [hPa]Resolution [hPa]
3001100-2020+-1.70.01
3001100065+-1.00.01
110012502540+-1.50.01
7009002540+-1.2 (relative)0.0.1

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 humidity 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("Humidity = "));
    Serial.print(bme.readHumidity());
    Serial.println(" %RH");

    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 humidity 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("Humidity = "));
    Serial.print(bme.readHumidity());
    Serial.println(" %RH");

    delay(delayTime);
}

Similar Posts

2 Comments

  1. Ahoj Lukas. Pls pisem ohladom Marlin na Kossel , tam sa neda pridat koment. Pls vsetko je OK ale nefunguje mi babystep ked chcem pouzit baby tak to zmrzne. nevies poradit ?

    1. Jsou tam nastavené FB komentáře.
      Asi to stejně přepnu na standard zpět.

      Flashni tam mou novou verzi 2.0.0, tam je babystepping ořešený.

Leave a Reply

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