BME680环境传感器

简介

BME680环境传感器是一款四合一MEMS环境传感器,可测量VOC(挥发性有机物)、温度、湿度、气压这四个参数,非常适用于监测空气质量。由于采用了MEMS技术,该传感器体积小、功耗低,因此也适用于低功耗场合,如可穿戴等。 DFRobot Gravity BME680环境传感器采用Gravity I2C接口,即插即用,连线简单方便;板载电源稳压芯片和电平信号转换芯片,兼容性好,可直接兼容3.3V和5V系统;预留了SPI接口,方便做扩展。本产品集成度高,可同时检测四个环境参数,是气象站、智能家居、物联网、可穿戴等场景的理想选择。 使用本产品,可迅速搭建出一套空气质量检测仪。当今空气污染越来越严重,有毒物质超标的家具屡屡出现,因此是时候为自己的健康把关了。

技术规格

IAQ(室内空气质量)对照表

室内空气质量指数对照表

引脚说明



BME680环境传感器引脚说明

标号 名称 功能描述
+ VCC 3.3~5V
- GND GND
C SCL I2C-SCL
D SDA I2C-SDA

使用教程

本教程将演示如何使用这个传感器模块。 目前,只有FireBeetle ESP8266 WiFi 物联网开发板能读取IAQ数值,其他主控器暂不支持。

准备

硬件

软件

接线图

I2C连接图

请务必注意线序,VCC接电源,GND接地


SPI连接图

请务必注意线序,VCC接3.3V,GND接地



样例代码

请先安装Arduino库文件,点击下载 本样例代码采用I2C接口。SPI接口的样例代码请至库文件中查找DFRobot_BME680_SPI.ino文件,由于功能一致,不在此展示代码。 为准确测量海拔值,需要进行校准。上传代码前,请将您所在地区的海拔值填入样例代码中的语句中:seaLevel = bme.readSeaLevel(您所在地区的海拔值);

读取数据(无IAQ指数)

程序功能:读取传感器数据,并进行串口打印。(不带IAQ)

/*
       file DFRobot_BME680_I2C.ino

       @ https://github.com/DFRobot/DFRobot_BME680

       connect bme680 I2C interface with your board (please reference board compatibility)

       Temprature, Humidity, pressure, altitude, calibrate altitude and gas resistance data will print on serial window.

       Copyright   [DFRobot](http://www.dfrobot.com), 2016
       Copyright   GNU Lesser General Public License

       version  V1.0
       date  2017-12-7
*/

#include "DFRobot_BME680_I2C.h"
#include "Wire.h"

/*use an accurate altitude to calibrate sea level air pressure*/
#define CALIBRATE_PRESSURE

DFRobot_BME680_I2C bme(0x77);  //0x77 I2C address

float seaLevel;
void setup()
{
  uint8_t rslt = 1;
  Serial.begin(9600);
  while (!Serial);
  delay(1000);
  Serial.println();
  while (rslt != 0) {
    rslt = bme.begin();
    if (rslt != 0) {
      Serial.println("bme begin failure");
      delay(2000);
    }
  }
  Serial.println("bme begin successful");
#ifdef CALIBRATE_PRESSURE
  bme.startConvert();
  delay(1000);
  bme.update();
  /*You can use an accurate altitude to calibrate sea level air pressure.
    And then use this calibrated sea level pressure as a reference to obtain the calibrated altitude.
    In this case,525.0m is chendu accurate altitude.
  */
  seaLevel = bme.readSeaLevel(525.0);
  Serial.print("seaLevel :");
  Serial.println(seaLevel);
#endif
}

void loop()
{
  bme.startConvert();
  delay(1000);
  bme.update();
  Serial.println();
  Serial.print("temperature(C) :");
  Serial.println(bme.readTemperature() / 100, 2);
  Serial.print("pressure(Pa) :");
  Serial.println(bme.readPressure());
  Serial.print("humidity(%rh) :");
  Serial.println(bme.readHumidity() / 1000, 2);
  Serial.print("gas resistance(ohm) :");
  Serial.println(bme.readGasResistance());
  Serial.print("altitude(m) :");
  Serial.println(bme.readAltitude());
#ifdef CALIBRATE_PRESSURE
  Serial.print("calibrated altitude(m) :");
  Serial.println(bme.readCalibratedAltitude(seaLevel));
#endif
}

读取数据(带IAQ数值)

程序功能:读取传感器数据,并进行串口打印。(带IAQ) 目前,只有FireBeetle ESP8266 WiFi物联网开发板能读取IAQ数值,其他主控器暂不支持。 对于FireBeetle ESP8266 WiFi物联网开发板,请使用Arduino IDE 1.8版本,并需要将SDK升级至2.3.1及以上。升级方法参考FireBeetle ESP8266维库的第5.2节内容。

/*
       file DFRobot_BME680_I2C.ino

       @ https://github.com/DFRobot/DFRobot_BME680

       connect bme680 I2C interface with your board (please reference board compatibility)

       Temprature, Humidity, pressure, altitude, calibrated altitude, gas resistance and IAQ data will be printed via serial.

       Copyright   [DFRobot](http://www.dfrobot.com), 2016
       Copyright   GNU Lesser General Public License

       version  V1.0
       date  2017-12-7
*/

#include "DFRobot_BME680_I2C.h"
#include "Wire.h"

/*use an accurate altitude to calibrate sea level air pressure*/
#define CALIBRATE_PRESSURE

DFRobot_BME680_I2C bme(0x77);  //0x77 I2C address


float seaLevel;
void setup()
{
  uint8_t       rslt = 1;
  Serial.begin(115200);
  while (!Serial);
  delay(1000);
  Serial.println();
  while (rslt != 0) {
    rslt = bme.begin();
    if (rslt != 0) {
      Serial.println("bme begin failure");
      delay(2000);
    }
  }
  Serial.println("bme begin successful");
  bme.supportIAQ();
}

void loop()
{
  static uint8_t       calibrated = 0;

#ifdef CALIBRATE_PRESSURE
  if (calibrated == 0) {
    if (bme.iaqUpdate() == 0) {
      /*You can use an accurate altitude to calibrate sea level air pressure.
        And then use this calibrated sea level pressure as a reference to obtain the calibrated altitude.
        In this case,525.0m is chendu accurate altitude.
      */
      seaLevel = bme.readSeaLevel(525.0);
      Serial.print("seaLevel :");
      Serial.println(seaLevel);
      calibrated = 1;
    }
  }
#else
  calibrated = 1;
#endif

  if (calibrated) {
    uint8_t rslt = bme.iaqUpdate();
    if (rslt == 0) {
      Serial.println();
      Serial.print("timestamp(ms) :");
      Serial.println(millis());
      Serial.print("temperature(C) :");
      Serial.println(bme.readTemperature(), 2);
      Serial.print("pressure(Pa) :");
      Serial.println(bme.readPressure());
      Serial.print("humidity(%rh) :");
      Serial.println(bme.readHumidity(), 2);
      Serial.print("altitude(m) :");
      Serial.println(bme.readAltitude());
#ifdef CALIBRATE_PRESSURE
      Serial.print("calibrated altitude(m) :");
      Serial.println(bme.readCalibratedAltitude(seaLevel));
#endif
      Serial.print("gas resistance :");
      Serial.println(bme.readGasResistance());
      if (bme.isIAQReady()) {
        Serial.print("IAQ :");
        float iaq = bme.readIAQ();
        Serial.print(iaq);
        if (iaq < 50) Serial.println(" good");
        else if (iaq < 100) Serial.println(" average");
        else if (iaq < 150) Serial.println(" little bad");
        else if (iaq < 200) Serial.println(" bad");
        else if (iaq < 300) Serial.println(" worse");
        else Serial.println(" very bad");
      } else {
        Serial.print("IAQ not ready, please wait about ");
        Serial.print((int)(305000 - millis()) / 1000);
        Serial.println(" seconds");
      }
    }
  }
}

结果

无IAQ数据

BME680_result.png

带IAQ数据

BME680_result_iaq.png

Arduino库函数功能列表

兼容性测试

MCU 测试通过 测试失败 未测试 特别标注
FireBeetle-Board328P 不支持IAQ
FireBeetle-ESP32 不支持IAQ
FireBeetle-ESP8266 支持IAQ
Leonardo 不支持IAQ

Mind+(基于Scratch3.0)图形化编程

  1. 下载及安装软件。下载地址:http://www.mindplus.cc 详细教程:Mind+基础wiki教程-软件下载安装
  2. 切换到“上传模式”。 详细教程:Mind+基础wiki教程-上传模式编程流程
  3. “扩展”中选择“主控板”中的“Arduino Uno”。 “扩展”“传感器”中搜索选择“BME680模块”,详细教程:Mind+基础wiki教程-加载扩展库流程
  4. 进行编程,程序如下图:
  5. 菜单“连接设备”,“上传到设备”
  6. 程序上传完毕后,打开串口即可看到数据输出。详细教程:Mind+基础wiki教程-串口打印

常见问题

还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。

更多

DFshopping_car1.png DFRobot商城购买链接