原文链接:https://www.yourcee.com/newsinfo/2929148.html
BME680简介
BME680是一种温度、湿度、气压、有机挥发性化合物的四合一数字环境检测传感器(VOC)。用于测量空气中的金属氧化物敏感元件VOCs,不同VOCs浓度下金属氧化物表面的电导率不一样从而输出不同的电阻值。这个传感器可以给周围的空气一个VOCs与特定的气体分子相比,污染物之和的定性概念。
敏感元件 | 测量范围 | 精度 |
---|---|---|
温度 | -40 to 85 oC | /- 1.0 oC |
湿度 | 0 to 100 % | /- 3 % |
气压 | 300 to 1100 hPa | /- 1 hPa |
接口说明
BME680与Arduino UNO接线与程序
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小时后其测量的数据相对稳定准确,建议使传感器工作半小时后读取到的气敏电阻值相对准确。通过本实验能快速直观的使用传感器获取所处环境的参数。