Using BME280 sensor for Humidity, Barometric Pressure and Temperature.

I’m interested in measuring these parameters (Humidity, Barometric Pressure and Temperature) to collect information using many low costs sensors along the Geophysical Network for several purposes.

So I’m experimenting with several low cost sensors to see how they do and whether they are suitable for the task.

In this case we are testing the BME280 integrated environmental sensor. It was developed specifically for mobile applications where size and low power consumption are key design constraints. See here. It is a Temperature Humidity Pressure Sensor, I2C and SPI capable. So it can be connected through any of both protocols.

In this example we use an Arduino UNO R3 compatible Red and a GY-BME280-3.3 High Precision Barometric Pressure Module – Purple board. Notice that there are plenty of providers of BME280 modules and Arduino compatible boards, and the order of the pins may vary from one to another. So do check where are those pins in your board.

We use cactus.io BME280 SPI library. Many other Libraries will work also. But you’ll have to change the library include and also some libraries may have different names in the BME object creation an in its methods. Also the creation of the BME_SPI object depends whether the board has SPI hardware. In this case we do not. So we start an BME_SPI software connection. It will use the specified pins to communicate with the module. Notice that this library has option to add calibration parameters. The line “bme.setTempCal(-2);” will subtract two degrees to any reading in any temperature scale.

If you have problems compiling the SPI library included in Arduino IDE, you may have to update your Arduino IDE version. Download the new version and install with the install.sh script.

Your BME280 module has at least the following pins:

VCC/VIN //5Volt input
GND // Ground connection
SCK/SCL  // Serial Clock
MISO/SDA/SDI  // Serial Data Out
MOSI/SDO  // Serial Data In
CS/CSB  // Chip Select

It may have an 3VO output that can be used to power some low power 3v device. Pin names may vary according to model.

For the SPI protocol (software connection) we must connect SCK/SCL to pin 13 of Arduino UNO, MOSI/SDO to pin 12 , MISO/SDA/SDI to pin 11 and CS/CSB to pin 10. If you have more than one module they are connected in parallel on SCK, MISO and MOSI but connect the other CS to another output pin.

Connect Arduino UNO and BME280 module as shown.

Open Arduino IDE and paste the following code:

/***************************************************************************
 BME280 humidity, temperature & pressure sensor test program with SPI bus
 ***************************************************************************/

#include “cactus_io_BME280_SPI.h”
#include “SPI.h”

// Communications pins order. Depends on your module
// Vcc Gnd Scl/Sck-13Sdo/Miso-12 Sdak/Mosi-11 Csb/Cs-10
#define BME_SCK 13 // Serial Clock
#define BME_MISO 12 // Serial Data Out
#define BME_MOSI 11 // Serial Data In
#define BME_CS 10 // Chip Select

// Create the BME280 object with the right pins
BME280_SPI bme(BME_CS,BME_MOSI,BME_MISO,BME_SCK);

void setup() {
Serial.begin(115200);
Serial.println(“Bosch BME280 Barometric Pressure – Humidity – Temp Sensor”);
if (!bme.begin()) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
}
bme.setTempCal(-1);
Serial.println(“PressuretHumditytTemp”);
}

void loop() {
bme.readSensor();
//Serial.print(bme.getPressure_MB()); Serial.print(“tt”); // Pressure in millibars
Serial.print(bme.getPressure_HP()); Serial.print(“tt”); // Pressure in hectapascals
Serial.print(bme.getHumidity()); Serial.print(“tt”);
Serial.print(bme.getTemperature_C()); Serial.println(” *Ct”); // temperature in Centigrades
//Serial.print(bme.getTemperature_F()); Serial.println(” *Ft”); // temperature in Fahrebheit
}

You compile and run this program and should read measurements in Serial Monitor.

Bosch BME280 Barometric Pressure - Humidity - Temp Sensor
Pressure Humdity Temp
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C 
101966.40 70.76 18.65 *C

Now your module is working.

If you want to try another library, this is the same example with Adafruit’s library. Check the methods and functions available for each library, to find the one that best fits your needs.

/***************************************************************************
 BME280 humidity, temperature & pressure sensor test program with SPI bus
 ***************************************************************************/

#include “Adafruit_BME280.h”
#include “SPI.h”

// Communications pins order. Depends on your module
// Vcc Gnd Scl/Sck-13 Sdak/Mosi-11 Csb/Cs-10 Sdo/Miso-12
#define BME_SCK 13 // Serial Clock
#define BME_MISO 12 // Serial Data Out
#define BME_MOSI 11 // Serial Data In
#define BME_CS 10 // Chip Select

// Create the BME280 object with the right pins
//BME280_SPI bme(BME_CS,BME_MOSI,BME_MISO,BME_SCK);
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

void setup() {
Serial.begin(115200);
Serial.println(“Bosch BME280 Barometric Pressure – Humidity – Temp Sensor”);
if (!bme.begin()) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
}
Serial.println(“PressuretHumdityttTemp”);
}

void loop() {
bme.takeForcedMeasurement(); // has no effect in normal mode
Serial.print(bme.readPressure() / 100.0F); Serial.print(“tt”); // Pressure in hectapascals
Serial.print(bme.readHumidity()); Serial.print(“tt”);
Serial.print(bme.readTemperature()); Serial.println(” *Ct”); // temperature in Centigrades
}

Now a couple of pictures of the test set.

 

Related posts

Leave a Comment