Arduino UNO testing BME680 environmental sensor

Introduction to BME680

The BME680 is a four-in-one digital environmental detection sensor that can measure the temperature, humidity, air pressure, and volatile organic compounds (VOC) of the surrounding environment. The internal metal oxide sensitive element is used to measure VOCs in the air. The conductivity of the metal oxide surface is different under different VOCs concentrations and thus outputs different resistance values. This sensor can give a qualitative idea of ​​the sum of VOCs/pollutants in the surrounding air, rather than specific gas molecules.
insert image description here

sensitive components Measuring range accuracy
temperature -40 to 85 ºC +/- 1.0 ºC
humidity 0 to 100 % +/- 3 %
air pressure 300 to 1100 hPa +/- 1 hPa

Interface Description

insert image description here
VCC Power supply positive 3.3-5V
GND Power supply negative
SCL SPI/IIC mode clock signal input
SDA SPI mode MOSI data signal input, IIC mode data signal input and output
SDO SPI mode MISO data signal output, in IIC mode: IIC device address setting pin, when connected to GND, the device address is 1110110 (0x76), when connected to VCC, the device address is 1110111 (0x77)
CS SPI/IIC mode selection pin, when connected to VCC it is IIC mode, when connected to GND for SPI mode

BME680 and Arduino UNO wiring and program

BME680 SPI wiring method IIC wiring method
SCL D13 A5
SDA D11 A4
SDO D12 /
CS D10 /

IIC wiring method

Arduino IDE library manager install Adafruit_BME680 library
insert image description here
Arduino IDE library manager install Adafruit Unified SensorOpen
insert image description here
example code

/***************************************************************************
  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);
}

Open the serial monitor to display the data measured by the sensor
insert image description here

Summarize

When using the sensor for the first time, it is recommended that the measured data be relatively stable and accurate after 48 hours of operation. This experiment can quickly and intuitively use the sensor to obtain the parameters of the environment.

Guess you like

Origin blog.csdn.net/qq_42250136/article/details/122330231