BME680是一個四合一數位環境檢測感測器,可以測量所處周圍環境的溫度、溼度、氣壓、有機揮發性化合物(VOC)。其內部的金屬氧化物敏感元件用於測量空氣中的VOCs,不同VOCs濃度下金屬氧化物表面的電導率不一樣從而輸出不同的電阻值。這個感測器能給到一個關於周圍空氣中VOCs/汙染物之和的定性概念,而不是特定的氣體分子。
敏感元件 | 測量範圍 | 精度 |
---|---|---|
溫度 | -40 to 85 ºC | +/- 1.0 ºC |
溼度 | 0 to 100 % | +/- 3 % |
氣壓 | 300 to 1100 hPa | +/- 1 hPa |
VCC 供電正極3.3-5V
GND 供電負極
SCL SPI/IIC模式時鐘訊號輸入
SDA SPI模式的MOSI資料訊號的輸入,IIC模式的資料訊號的輸入和輸出
SDO SPI模式的MISO資料訊號的輸出,IIC模式時為IIC器件地址設定引腳,接GND時器件地址為1110110(0x76),接VCC時器件地址為1110111(0x77)
CS SPI/IIC模式的選擇引腳,當接VCC時為IIC模式,當接GND時為SPI模式
BME680 | SPI接線方式 | IIC接線方式 |
---|---|---|
SCL | D13 | A5 |
SDA | D11 | A4 |
SDO | D12 | / |
CS | D10 | / |
IIC接線方式
Arduino IDE庫管理器安裝 Adafruit_BME680 library
Arduino IDE庫管理器安裝Adafruit Unified Sensor
開啟範例程式碼
/***************************************************************************
This is a library for the BME680 gas, humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME680 Breakout
----> http://www.adafruit.com/products/3660
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C
//Adafruit_BME680 bme(BME_CS); // hardware SPI
//Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println(F("BME680 async test"));
if (!bme.begin()) {
Serial.println(F("Could not find a valid BME680 sensor, check wiring!"));
while (1);
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop() {
// Tell BME680 to begin measurement.
unsigned long endTime = bme.beginReading();
if (endTime == 0) {
Serial.println(F("Failed to begin reading :("));
return;
}
Serial.print(F("Reading started at "));
Serial.print(millis());
Serial.print(F(" and will finish at "));
Serial.println(endTime);
Serial.println(F("You can do other work during BME680 measurement."));
delay(50); // This represents parallel work.
// There's no need to delay() until millis() >= endTime: bme.endReading()
// takes care of that. It's okay for parallel work to take longer than
// BME680's measurement time.
// Obtain measurement results from BME680. Note that this operation isn't
// instantaneous even if milli() >= endTime due to I2C/SPI latency.
if (!bme.endReading()) {
Serial.println(F("Failed to complete reading :("));
return;
}
Serial.print(F("Reading completed at "));
Serial.println(millis());
Serial.print(F("Temperature = "));
Serial.print(bme.temperature);
Serial.println(F(" *C"));
Serial.print(F("Pressure = "));
Serial.print(bme.pressure / 100.0);
Serial.println(F(" hPa"));
Serial.print(F("Humidity = "));
Serial.print(bme.humidity);
Serial.println(F(" %"));
Serial.print(F("Gas = "));
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(F(" KOhms"));
Serial.print(F("Approx. Altitude = "));
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(F(" m"));
Serial.println();
delay(2000);
}
開啟串列埠監視器顯示出感測器測量的資料
首次使用感測器器時建議使其工作48小時後其測量的資料相對穩定準確,建議使感測器工作半小時後讀取到的氣敏電阻值相對準確。通過本實驗能快速直觀的使用感測器獲取所處環境的引數。