Arduino BME280 sensor example

The BME280 is a humidity sensor features an extremely fast response time which supports performance requirements for emerging applications such as context awareness, and high accuracy over a wide temperature range. The pressure sensor is an absolute barometric pressure sensor with features exceptionally high accuracy and resolution at very low noise. The integrated temperature sensor has been optimized for very low noise and high resolution. It is primarily used for temperature compensation of the pressure and humidity sensors, and can also be used for estimating ambient temperature.

The best way to use the device is a module like the one pictured below

bme280-module

I found this schematic for a breakout online for the bme280, you’ll see in the sparkun image above they are using 4k7’s rather than 10K

Sparkfun has all of the design files for their module available from https://github.com/sparkfun/SparkFun_BME280_Breakout_Board ,

bme280-module-schematic

You can use this module in either SPI or I2C modes, in this case we went for SPI mode, here is the wiring for our module to our arduino Uno

Connect Vin to 5V.
Connect GND to ground
Connect the SCK pin to Digital #13
Connect the SDO pin to Digital #12
Connect the SDI pin to Digital #11
Connect the CS pin Digital #10

Code

The code uses the sparkfun library, I tried 2 others and couldn’t get them to compile. There are several examples available. I removed some code from a basic example

Library – https://github.com/sparkfun/SparkFun_BME280_Arduino_Library

#include <stdint.h>
#include "SparkFunBME280.h"
#include "Wire.h"
#include "SPI.h"
 
//Global sensor object
BME280 mySensor;
 
void setup()
{
  Serial.begin(57600);
  //SPI
  mySensor.settings.commInterface = SPI_MODE;
  mySensor.settings.chipSelectPin = 10;
 
  //Operation settings
  mySensor.settings.runMode = 3; //Normal mode
  mySensor.settings.tStandby = 0;
  mySensor.settings.filter = 0;
  mySensor.settings.tempOverSample = 1;
  mySensor.settings.pressOverSample = 1;
  mySensor.settings.humidOverSample = 1;
 
  Serial.print("Starting BME280... result of .begin(): 0x");
  delay(10);  //BME280 requires 2ms to start up.
  Serial.println(mySensor.begin(), HEX);
 
}
 
void loop()
{
  //Each loop, take a reading.
 
  Serial.print("Temperature: ");
  Serial.print(mySensor.readTempC(), 2);
  Serial.println(" degrees C");
 
  Serial.print("Temperature: ");
  Serial.print(mySensor.readTempF(), 2);
  Serial.println(" degrees F");
 
  Serial.print("Pressure: ");
  Serial.print(mySensor.readFloatPressure(), 2);
  Serial.println(" Pa");
 
  Serial.print("Altitude: ");
  Serial.print(mySensor.readFloatAltitudeMeters(), 2);
  Serial.println("m");
 
  Serial.print("Altitude: ");
  Serial.print(mySensor.readFloatAltitudeFeet(), 2);
  Serial.println("ft"); 
 
  Serial.print("%RH: ");
  Serial.print(mySensor.readFloatHumidity(), 2);
  Serial.println(" %");
 
  Serial.println();
 
  delay(1000);
 
}

Output

All going well if you open your serial monitor window you should see something like this

Temperature: 22.55 degrees C
Temperature: 72.61 degrees F
Pressure: 100637.00 Pa
Altitude: 59.39m
Altitude: 194.01ft
%RH: 0.00 %

Temperature: 22.54 degrees C
Temperature: 72.57 degrees F
Pressure: 100640.00 Pa
Altitude: 59.13m
Altitude: 194.58ft
%RH: 0.00 %

Temperature: 22.53 degrees C
Temperature: 72.59 degrees F
Pressure: 100638.00 Pa
Altitude: 59.31m
Altitude: 195.99ft
%RH: 0.00 %

The temperature looked accurate, I looked up the air pressure and altitude of my location on the internet. Not bad on air pressure as I looked it up a bit later than when I gathered the readings

Pressure 1011.2 mb, Steady [Min 1010.5 Max 1012.5]

Altitude was about 40m out, according to http://elevationmap.net. I’ll need to investigate this as that’s not that good

 

Links

You can pick up one of these breakout/modules for under $8
BME280 Embedded high-precision barometric pressure sensor module