itbrainpower.net
THE ALPHABET PROJECT - professional Arduino, BeagleBone & Raspberry PI shields

 
COVID19-SARS2 service info ==> we are 100% up and running!

Order here our IoT product(s) of the week.

Arduino BME680 sensor how to

 

About BME680 - temperature, humidity, pressure and gas sensor


Bosch BME680 it's 4-in-1 sensor with gas, humidity, pressure and temperature measurement based on proven sensing principles and having very low power consumption. Main measurement characteristics:
- ambient range for operation -40 ~ +85C, 0%-100% r.H., 300-1100hPa
- resolution of gas sensor resistance measurement 0.05-0.11%
- bVOC tolerance/certified accuracy 10-20% / 2-5%
- humidity accuracy +-3%
- absolute temperature (0-65C) accuracy +-1C
- absolute/relative pressure accuracy +-0.6hPa/+-0.12hPa
More info on: BME680 datasheet

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

s-Sense BME680 sensor breakout by itbrainpower.net

BME680 sensor breakout - topBME680 sensor breakout - bottom

PN: SS-BME680#I2C   SKU: ITBP-6003   BME680 I2C sensor breakout info

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

 

 

 

Arduino BME680 sensor hardware integration (wiring)


First, identify if your Arduino it's 5V or 3.3V compliant!

The BME680 I2C sensor breakout it's shipped in default auto 3-5V compliant configuration. In a nut shell, wire as bellow:

BME680 breakout Arduino 5V [Eg.: UNO] Arduino 3.3V [Eg.: Zero]
Vin PAD 5V 3.3V
Vdd PAD (3V3) do not connect do not connect
SDA PAD SDA SDA
SCL PAD SCL SCL
GND PAD GND GND
 

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 modems]:
BME680 sensor breakout Arduino shield wiring


Bellow, sensor wiring example with Arduino UNO shield [328p, 5 compliant]:

BME680 sensor breakout wiring with Arduino UNO shield


Arduino BME680 sensor software - read raw sensor data


a. download BME680 Arduino library from: here.

b. unzip the library and install in Arduino libraries folder. Restart Arduino.

c. Make a folder named "ssense_BME680_example".
Copy the code bellow, paste it one new file and save the file as "ssense_BME680_example.ino" in the folder created in previously or, you may download it from here (right click & save as): BME680 - read sensor data Arduino code

1/* s-Sense BME680 I2C sensor breakout example - v1.0/20190524. 
2 * 
3 * Compatible with:
4 *    s-Sense BME680 I2C sensor breakout - temperature, humidity, pressure and gas - [PN: SS-BME680#I2C, SKU: ITBP-6003], 
5 *    info https://itbrainpower.net/sensors/BME680-BVOC-TEMPERATURE-HUMIDITY-PRESSURE-I2C-sensor-breakout 
6 *
7 * This code shows how to use predefined recommended settings for the BME680 air quality sensor. Read temperature,  
8 * humidity, pressure and gas sensor data (pulling at 1sec) - code based on based on Zanshin_BME680 library version 
9 * 1.0.2 / 2019-01-26 - https://github.com/SV-Zanshin . Good job Zanshin!
10 *  
11 * Include three functions for altitude calculation (one provided by Zanshin, one ported from BME280/BMP280 library [NOAA equation] and the
12 * last one [based on CASIO equation and implementing temperature compensated algorithm] that was written by us.
13 *  
14 * We've just select the relevant functions, fixed some 328p compiling issues found in original library, add some variables, functions and fuctionalities.
15 * 
16 * 
17 * Mandatory wiring:
18 *    Common for 3.3V and 5V Arduino boards:
19 *        sensor I2C SDA  <------> Arduino I2C SDA
20 *        sensor I2C SCL  <------> Arduino I2C SCL
21 *        sensor GND      <------> Arduino GND
22 *    For Arduino 3.3V compatible:
23 *        sensor Vin      <------> Arduino 3.3V
24 *    For Arduino 5V compatible:
25 *        sensor Vin      <------> Arduino 5V
26 * 
27 * Leave other sensor PADS not connected.
28 * 
29 * SPECIAL note for some ARDUINO boards:
30 *        SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
31 *        SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
32 * 
33 * WIRING WARNING: wrong wiring may damage your Arduino board MCU or your sensor! Double check what you've done.
34 * 
35 * New BME680 sensors requires burn in. Once burned in a sensor requires at least 5 minutes of run in before gas resistance readings are considered good.  
36 * 
37 * READ BME680 documentation! https://itbrainpower.net/sensors/BME680-BVOC-TEMPERATURE-HUMIDITY-PRESSURE-I2C-sensor-breakout
38 * 
39 * We ask you to use this SOFTWARE only in conjunction with s-Sense BME680 sensor breakout usage. Modifications, derivates 
40 * and redistribution of this SOFTWARE must include unmodified this notice. You can redistribute this SOFTWARE and/or modify it under the 
41 * terms of this notice. 
42 * 
43 * 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 
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
45 *  
46 * itbrainpower.net invests significant time and resources providing those how to and in design phase of our IoT products.
47 * Support us by purchasing our environmental and air quality sensors from https://itbrainpower.net/order#s-Sense
48 *
49 *
50 * Dragos Iosub, Bucharest 2019.
51 * https://itbrainpower.net
52 */
53
54 /*! @file I2CDemo.ino
55
56
57@section I2CDemo_intro_section Description
58
59Example program for using the Bosch BME680 sensor. The sensor measures temperature, pressure and humidity and  is
60described at https://www.bosch-sensortec.com/bst/products/all_products/BME680. The datasheet is available from Bosch
61at https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME680_DS001-11.pdf \n\n
62
63The most recent version of the BME680 library is available at https://github.com/SV-Zanshin/BME680 and the 
64documentation of the library as well as example programs are described in the project's wiki pages located at 
65https://github.com/SV-Zanshin/BME680/wiki. \n\n
66
67The BME680 is a very small package so it is unlikely for an Arduino hobbyist to play around with directly, the 
68hardware used to develop this library is a breakout board from AdaFruit which is well-documented at
69https://learn.adafruit.com/adafruit-BME680-humidity-barometric-pressure-temperature-sensor-breakout \n\n
70
71This example program initializes the BME680 to use I2C for communications. The library does not using floating
72point mathematics to save on computation space and time, the values for Temperature, Pressure and Humidity are
73returned in deci-units, e.g. a Temperature reading of "2731" means "27.31" degrees Celsius. The display in the 
74example program uses floating point for demonstration purposes only.  Note that the temperature reading is 
75generally higher than the ambient temperature due to die and PCB temperature and self-heating of the element.\n\n
76
77The pressure reading needs to be adjusted for altitude to get the adjusted pressure reading. There are numerous
78sources on the internet for formula converting from standard sea-level pressure to altitude, see the data sheet
79for the BME180 on page 16 of http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf. Rather than put a
80floating-point function in the library which may not be used but which would use space, an example altitude
81computation function has been added to this example program to show how it might be done.
82
83@section I2CDemolicense License
84
85This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
86Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
87option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
88WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89GNU General Public License for more details. You should have received a copy of the GNU General Public License
90along with this program.  If not, see <http://www.gnu.org/licenses/>.
91
92@section I2CDemoauthor Author
93
94Written by Arnd\@SV-Zanshin
95
96@section I2CDemoversions Changelog
97
98Version | Date       | Developer           | Comments
99------- | ---------- | ------------------- | --------
1001.0.1   | 2019-01-26 | https://github.com/SV-Zanshin | Issue #3 - convert documentation to Doxygen
1011.0.0b  | 2018-06-30 | https://github.com/SV-Zanshin | Cloned from original BME280 program
102
103*/
104
105/*******************************************************************************************************************
106**                                                                                                                **
107** This program is free software: you can redistribute it and/or modify it under the terms of the GNU General     **
108** Public License as published by the Free Software Foundation, either version 3 of the License, or (at your      **
109** option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY     **
110** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   **
111** GNU General Public License for more details. You should have received a copy of the GNU General Public License **
112** along with this program.  If not, see <http://www.gnu.org/licenses/>.                                          **
113**                                                                                                                **
114** Vers.  Date       Developer                     Comments                                                       **
115** ====== ========== ============================= ============================================================== **
116** 1.0.0b 2018-06-30 https://github.com/SV-Zanshin Cloned from original BME280 program                            **
117**                                                                                                                **
118*******************************************************************************************************************/
119#include "sSense_BME680.h" // Include the BME680 Sensor library
120/*******************************************************************************************************************
121** Declare all program constants                                                                                  **
122*******************************************************************************************************************/
123
124#define SERIAL_SPEED  19200//; ///< Set the baud rate for Serial I/O
125/*******************************************************************************************************************
126** Declare global variables and instantiate classes                                                               **
127*******************************************************************************************************************/
128BME680_Class BME680; ///< Create an instance of the BME680
129
130/*!
131* @brief     This converts a pressure measurement into a height in meters
132* @details   The corrected sea-level pressure can be passed into the function if it is know, otherwise the standard 
133*            atmospheric pressure of 1013.25hPa is used (see https://en.wikipedia.org/wiki/Atmospheric_pressure
134* @param[in] seaLevel Sea-Level pressure in millibars
135* @return    floating point altitude in meters.
136*/
137float altitude(const float seaLevel=1013.25) 
138{
139  /*wikipedia equation - original Zanshin code*/
140  static float Altitude;
141  int32_t temp, hum, press, gas;
142  BME680.getSensorData(temp,hum,press,gas); // Get the most recent values from the device
143  Altitude = 44330.0*(1.0-pow(((float)press/100.0)/seaLevel,0.1903)); // Convert into altitude in meters
144  return(Altitude);
145} // of method altitude()
146
147float calculate_altitude( float pressure, bool metric = true, float seaLevelPressure = 101325)
148{
149  /*Equations courtesy of NOAA - code ported from BME280*/;
150  float altitude = NAN;
151  if (!isnan(pressure) && !isnan(seaLevelPressure)){
152    altitude = 1000.0 * ( seaLevelPressure - pressure ) / 3386.3752577878;
153  }
154  return metric ? altitude * 0.3048 : altitude;
155}
156
157float temperatureCompensatedAltitude(int32_t pressure, float temp=21.0 /*Celsius*/, float seaLevel=1013.25) 
158{
159  /*Casio equation - code written by itbrainpower.net*/
160  float Altitude;
161  Altitude = (pow((seaLevel/((float)pressure/100.0)), (1/5.257))-1)*(temp + 273.15) / 0.0065; // Convert into altitude in meters
162  return(Altitude); //this are metric value
163
164
165
166/*!
167    @brief    Arduino method called once at startup to initialize the system
168    @details  This is an Arduino IDE method which is called first upon boot or restart. It is only called one time
169              and then control goes to the main "loop()" method, from which control never returns
170    @return   void
171*/
172void setup()
173{
174  DebugPort.begin(SERIAL_SPEED); // Start serial port at Baud rate
175
176  while(!DebugPort) {delay(10);} // Wait
177
178  //delay(1000);
179
180  DebugPort.println("s-Sense BME680 I2C sensor.");
181  DebugPort.print("- Initializing BME680 sensor\n");
182  while (!BME680.begin(I2C_STANDARD_MODE)) // Start BME680 using I2C protocol
183  {
184    DebugPort.println("-  Unable to find BME680. Waiting 1 seconds.");
185    delay(1000);
186  } // of loop until device is located
187  DebugPort.println("- Setting 16x oversampling for all sensors");
188  BME680.setOversampling(TemperatureSensor,Oversample16); // Use enumerated type values
189  BME680.setOversampling(HumiditySensor,   Oversample16);
190  BME680.setOversampling(PressureSensor,   Oversample16);
191  DebugPort.println("- Setting IIR filter to a value of 4 samples");
192  BME680.setIIRFilter(IIR4);
193  DebugPort.println("- Setting gas measurement to 320C for 150ms");
194  BME680.setGas(320,150); // 320�c for 150 milliseconds
195  DebugPort.println();
196} // of method setup()
197
198/*!
199    @brief    Arduino method for the main program loop
200    @details  This is the main program for the Arduino IDE, it is an infinite loop and keeps on repeating. 
201    @return   void
202*/
203void loop() 
204{
205  //static uint8_t loopCounter = 0;
206  static int32_t temperature, humidity, pressure, gas;     // Variable to store readings
207  BME680.getSensorData(temperature,humidity,pressure,gas); // Get most recent readings
208  DebugPort.print("\r\nSensor data >>\t\t");                       // Temperature in deci-degrees
209  DebugPort.print(temperature/100.0,2);                       // Temperature in deci-degrees
210  DebugPort.print("C\t");                          
211  DebugPort.print(humidity/1000.0,2);                         // Humidity in milli-percent
212  DebugPort.print("%\t");
213  DebugPort.print(pressure/100.0,2);                          // Pressure in Pascals
214  DebugPort.print("hPa\t");
215  //DebugPort.print(pressure);                          // Pressure in Pascals
216  //DebugPort.print("Pa ");
217  DebugPort.print(gas/100.0,2);
218  DebugPort.println("mOhm");
219
220  DebugPort.println("\r\nCalculated altitude");
221
222  DebugPort.print("temp comp [CASIO equation]: ");
223
224  //temperatureCompensatedAltitude(int32_t pressure, float temp =21.0, const float seaLevel=1013.25)
225  DebugPort.print(temperatureCompensatedAltitude(pressure, temperature/100.0/*, 1022.0*/),2); 
226  DebugPort.print("m\t");
227
228
229  DebugPort.print("NOAA equation: ");
230
231  //float calculate_altitude( float pressure, bool metric = true, float seaLevelPressure = 101325)
232  DebugPort.print(calculate_altitude((long)pressure,true),2); //calculate_altitude
233  //DebugPort.print(calculate_altitude((long)pressure,true, (long)102200.0),2); //calculate_altitude
234  DebugPort.print("m\t");
235
236  DebugPort.print("WIKI equation: ");
237  DebugPort.print(altitude(),2); 
238  DebugPort.println("m \r\n");
239/*  
240Temp: 33.03C            Humidity: 42.03% RH             Pressure: 101058.02 Pa
241Altitude: 78.84m        Dew point: 12.43C               Equivalent Sea Level Pressure: 101950.37 Pa
242
243Temp: 33.01C            Humidity: 40.75% RH             Pressure: 101051.84 Pa
244Altitude: 80.66m        Dew point: 11.71C               Equivalent Sea Level Pressure: 101964.92 Pa
245
246Temp: 32.98C            Humidity: 40.24% RH             Pressure: 101055.34 Pa
247Altitude: 79.63m        Dew point: 11.40C               Equivalent Sea Level Pressure: 101956.80 Pa
248 */
249  delay(1000);
250} // of method loop()
251


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).


Advanced sensor data interpretation - altitude calculation. We've included 3 variants:
- very basic algorithm,
- NOAA based algorithm (function ported from BME280/BMP280 Arduino library),
- CASIO altitude calculation implementation - most accurate altitude calculation based on temperature compensated algorithm...


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

 

 

 

 

 

 

Original how to written by Dragos Iosub & itbrainpower.net team

 

 

 

 

document version 0.921 / 2020-04-09 © R&D Software Solutions srl