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