Arduino BME280 Sensor How To

Arduino BME280 Sensor How To

Arduino how to - using BME280 (temp, hum and press sensor) I2C breakout from itbrainpower.net and Arduino 3.3V or 5V shields.

  • 367 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

Ide web
Arduino IDE
use version >=1.8.5

About this project

Bosch BME280 it's a digital temperature, humidity and pressure sensor. Main measurement characteristics:

  • ambient range for operation -40 ~ +85C, 0%-100% r.H., 300-1100hPa
  • humidity accuracy +-3%
  • absolute temperature (0-65C) accuracy +-1C
  • absolute/relative pressure accuracy +-0.6hPa/+-0.12hPa

More info on: BME280 datasheet

In June 2019 we've released 6 new environmental and air quality sensors, including Bosch Sensortec BME280, all being part of the s-Sense I2C sensor breakout family.

PN: SS-BME280#I2C SKU: ITBP-6002BME280 I2C sensor breakout info

Next, let's kickstart with BME280 sensor I2C breakout - around 10-15 minutes.

Arduino BMP280 sensor hardware integration (wiring)

First, identify if your Arduino it's 5V or 3.3V compliant! The BME280 I2C sensor breakout it's shipped in default auto 3-5V compliant configuration. In a nut shell, wire as bellow:

HINT, for some ARDUINO boards:

  • SDA (Serial Data) --> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
  • SCK (Serial Clock) --> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

Bellow, sensor wiring example with xyz-mIoT shield [AT SAMD21G, 3.3V compliant, with or without embedded modem]:

Arduino BME280 sensor software

  • a. download BME280/BMP280 Arduino library from: here.
  • b. unzip the library and install in Arduino libraries folder. Restart Arduino.
  • c. Make a folder named "ssense_BMx680_example". Download and save the code bellow (right click & save as): BME280 / BMP280 - read sensor data Arduino code
  • or, c'. The very same code it's available in Arduino "File-> Examples", under "ssense-BMx280" library.
  • d. Compile and upload the code to your Arduino shield. The sensor data may be seen on Arduino Serial Monitor (set to 19200bps).

What to do next:- you may like to run the "ssense_BMx280_Environment_Calculations.ino" example - available in Arduino "File-> Examples", under "ssense-BMx280" library.

TUTORIAL PROVIDED WITHOUT ANY WARRANTY!!! USE IT AT YOUR OWN RISK!!!!

Code

ssense_BMx280_example.inoArduino
Read and print BME280 [temperature, humidity and pressure] / BMP280 [temperature and pressure] sensor data - pulling rate ~ 1.5 second.

Just wire the sensor with your Arduino board. Select your board, compile and upload code. Set Serial Monitor at 19200bps.
/* s-Sense BME280 I2C / s-Sense BMP280 I2C sensor breakout example - v1.0/20190524. 
 * 
 * Compatible with:
 *    s-Sense BME280 I2C sensor breakout - temperature, humidity and pressure - [PN: SS-BME280#I2C, SKU: ITBP-6002], info https://itbrainpower.net/sensors/BME280-TEMPERATURE-HUMIDITY-PRESSURE-I2C-sensor-breakout 
 *    s-Sense BMP280 I2C sensor breakout - temperature and pressure - [PN: SS-BMP280#I2C, SKU: ITBP-6001], info https://itbrainpower.net/sensors/BMP280-TEMPERATURE-HUMIDITY-I2C-sensor-breakout
 *
 * This code shows how to use predefined recommended settings from Bosch for the BME280/BMP280 environmental sensor. Read temperature,  
 * humidity (unavailable for BMP280) and pressure (pulling at 1sec) - code based on BME280-2.3.0 library originally written by Tyler Glenn 
 * and forked by Alex Shavlovsky. Some part of code was written by Brian McNoldy. 
 * Amazing work folks! 
 * 
 * We've just select the relevant functions, add some variables, functions and fuctionalities.
 * 
 * 
 * Mandatory wiring:
 *    Common for 3.3V and 5V Arduino boards:
 *        sensor I2C SDA  <------> Arduino I2C SDA
 *        sensor I2C SCL  <------> Arduino I2C SCL
 *        sensor GND      <------> Arduino GND
 *    For Arduino 3.3V compatible:
 *        sensor Vin      <------> Arduino 3.3V
 *    For Arduino 5V compatible:
 *        sensor Vin      <------> Arduino 5V
 * 
 * Leave other sensor PADS not connected.
 * 
 * SPECIAL note for some ARDUINO boards:
 *        SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
 *        SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
 * 
 * WIRING WARNING: wrong wiring may damage your Arduino board MCU or your sensor! Double check what you've done.
 * 
 * READ BME280 documentation! https://itbrainpower.net/sensors/BME280-TEMPERATURE-HUMIDITY-PRESSURE-I2C-sensor-breakout
 * READ BMP280 documentation! https://itbrainpower.net/sensors/BMP280-TEMPERATURE-PRESSURE-I2C-sensor-breakout
 * 
 * We ask you to use this SOFTWARE only in conjunction with s-Sense BME280 I2C or s-Sense BMP280 I2C sensor breakout usage. Modifications, derivates 
 * and redistribution of this SOFTWARE must include unmodified this notice. You can redistribute this SOFTWARE and/or modify it under the 
 * terms of this notice. 
 * 
 * This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  
 * itbrainpower.net invests significant time and resources providing those how to and in design phase of our IoT products.
 * Support us by purchasing our environmental and air quality sensors from https://itbrainpower.net/order#s-Sense
 *
 *
 * Dragos Iosub, Bucharest 2019.
 * https://itbrainpower.net
 */

#define SERIAL_SPEED  19200

#include <sSense-BMx280I2C.h>
#include <Wire.h> 


/* Recommended Modes -
   Based on Bosch BME280I2C environmental sensor data sheet.

Weather Monitoring :
   forced mode, 1 sample/minute
   pressure ×1, temperature ×1, humidity ×1, filter off
   Current Consumption =  0.16 μA
   RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
   Data Output Rate 1/60 Hz

Humidity Sensing :
   forced mode, 1 sample/second
   pressure ×0, temperature ×1, humidity ×1, filter off
   Current Consumption = 2.9 μA
   RMS Noise = 0.07 %RH
   Data Output Rate =  1 Hz

Indoor Navigation :
   normal mode, standby time = 0.5ms
   pressure ×16, temperature ×2, humidity ×1, filter = x16
   Current Consumption = 633 μA
   RMS Noise = 0.2 Pa/1.7 cm
   Data Output Rate = 25Hz
   Filter Bandwidth = 0.53 Hz
   Response Time (75%) = 0.9 s


Gaming :
   normal mode, standby time = 0.5ms
   pressure ×4, temperature ×1, humidity ×0, filter = x16
   Current Consumption = 581 μA
   RMS Noise = 0.3 Pa/2.5 cm
   Data Output Rate = 83 Hz
   Filter Bandwidth = 1.75 Hz
   Response Time (75%) = 0.3 s

*/

BMx280I2C::Settings settings(
   BME280::OSR_X1,
   BME280::OSR_X1,
   BME280::OSR_X1,
   BME280::Mode_Forced,
   BME280::StandbyTime_1000ms,
   BME280::Filter_Off,
   BME280::SpiEnable_False,
   0x76 // I2C address. I2C specific.
);

BMx280I2C ssenseBMx280(settings);

//////////////////////////////////////////////////////////////////
void setup()
{
  delay(5000);
  DebugPort.begin(SERIAL_SPEED);

  while(!DebugPort) {} // Wait

  DebugPort.println("s-Sense BME/BMP280 I2C sensor.");

  Wire.begin();
  while(!ssenseBMx280.begin())
  {
    DebugPort.println("Could not find BME/BMP280 sensor!");
    delay(1000);
  }
  
  switch(ssenseBMx280.chipModel())
  {
     case BME280::ChipModel_BME280:
       DebugPort.println("Found BME280 sensor! Humidity available.");
       break;
     case BME280::ChipModel_BMP280:
       DebugPort.println("Found BMP280 sensor! No Humidity available.");
       break;
     default:
       DebugPort.println("Found UNKNOWN sensor! Error!");
  }

   // Change some settings before using.
   settings.tempOSR = BME280::OSR_X4;

   ssenseBMx280.setSettings(settings);
}

//////////////////////////////////////////////////////////////////
void loop()
{
   printBMx280Data(&DebugPort);
   delay(500);
}

//////////////////////////////////////////////////////////////////
void printBMx280Data
(
   Stream* client
)
{
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);

   ssenseBMx280.read(pres, temp, hum, tempUnit, presUnit);

   client->print("Temp: ");
   client->print(temp);
   //client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
   client->print(" "+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->println(" Pa");

   delay(1000);
}
Arduino BME280 and BMP280 libraryC/C++
Arduino library to access Bosch BME280 [temperature, humidity and pressure] and Bosch BME280 [temperature and pressure] sensor data - adapted for itbrainpower.net s-Sense BME280 I2C sensor breakout and itbrainpower.net s-Sense BME280 I2C sensor breakout -compatible with 3.3V - 5V Arduino shields.

This code it's based on BME280-2.3.0 library originally written by Tyler Glenn and forked by Alex Shavlovsky. Some part of original code was written by Brian McNoldy.

Extract and copy the class in Arduino Library folder - 'libraries' folder found in your Arduino Sketchbook. Take a look at "readme.md" and/or "readme.md" files.

Couple examples are available in Arduino "File-> Examples", under "ssense-BMx280" library.
No preview (download only).

Schematics

BME280 sensor wiring example with xyz-mIoT shield [AT SAMD21G, 3.3V compliant]
3.3V compliant Arduino board - wire as shown in the image.
For 5V compliant Arduino board, wire Vin to Arduino 5V pad NOT to 3.3V!!!
Bme280 arduino wiring howto 4d5mylksoc
BME280 breakout datasheet
s-Sense BME280 I2C sensor breakout datasheet

Comments

Similar projects you might like

Smoke Detection using MQ-2 Gas Sensor

by Aritro Mukherjee

  • 276,860 views
  • 47 comments
  • 175 respects

Using the YL-39 + YL-69 Soil Humidity Sensor with Arduino

Project tutorial by Sorin Trimbitas

  • 31,671 views
  • 6 comments
  • 20 respects

Arduino-Based Automatic Water Tap Using IR Sensor

Project tutorial by Creatjet3D R&D Team

  • 10,568 views
  • 6 comments
  • 23 respects

Create a Diving Computer with an MS5803–01BA Pressure Sensor

Project showcase by Varul Jain

  • 1,054 views
  • 2 comments
  • 2 respects
Add projectSign up / Login