Skip to content

BME690 Module Arduino Guide ​

Connect the BME690 Module to your controller board using a Grove cable to read temperature, relative humidity, pressure, and gas resistance, then print the readings over the serial port.

With the Bosch BSEC3 algorithm library, you can also read the indoor air quality index (IAQ) and CO₂ equivalent to observe changes in ambient air quality.

Things used in this project ​

Hardware components ​

BME690 Module
Environmental sensor module with a Grove connector

Software apps and online services ​

Arduino IDE
Compile and upload example code, and view serial output
B
Bosch-BME690-Library
Read temperature, pressure, humidity, and gas resistance
B
Bosch-BSEC3-Library
Run IAQ and CO₂ equivalent algorithms; install this library to read air quality data

Story ​

This project starts with raw sensor readings, then uses the BSEC3 algorithm to monitor air quality. Run the raw-data example first to verify the wiring and I2C communication before trying the IAQ example.

Set Up the Development Environment ​

  1. Install Arduino IDE and the board support package for your controller. For the ESP32-C3 TFT Devkit, see Getting Started with Arduino.
  2. Install or import Bosch-BME690-Library in Arduino IDE. It provides the Bme69x class for reading raw sensor data.
  3. To read IAQ, also install or import Bosch-BSEC3-Library. It provides the Bsec3 class for running the air quality algorithm.

BSEC3 Library Version

This guide uses the basic_config_state example from Bosch-BSEC3-Library. BSEC3 version 3.3.0.0 selects the BME690 bme69x driver by default, so BME690 projects do not need an additional macro. Define BSEC3_BME688 as a global compiler option only when switching to the BME688.

Before compiling, check src/bsec3.h and the installed examples/basic_config_state files. The example and the bsec_selectivity.c configuration must come from the same library version.

View Sensor Data ​

After uploading the example, open the Arduino IDE Serial Monitor and set the baud rate to 115200.

  • The raw-data example prints temperature (°C), pressure (Pa), relative humidity (%), and gas resistance (Ω).
  • The BSEC3 example prints these raw readings together with IAQ, IAQ accuracy, and CO₂ equivalent.

IAQ requires the algorithm to run continuously while it learns the environmental baseline. On first use, keep the module ventilated and allow the readings to stabilize.

CO₂ Equivalent

CO₂ equivalent is an algorithm estimate; the module does not directly measure CO₂ concentration.

Schematics ​

Connect the BME690 Module to the controller I2C interface using a Grove cable. A Qwiic cable or 2.54 mm jumper wires can also be used. Connect the signals as follows:

BME690 ModuleController Board
VCCModule power supply; confirm the voltage for your board and module revision
GNDGND
SDAI2C SDA
SCLI2C SCL

The examples initialize I2C with Wire.begin(). Make sure the default SDA and SCL pins match your wiring. For custom ESP32 pins, use Wire.begin(SDA_PIN, SCL_PIN) with the actual pin numbers.

The default I2C address is 0x76. If the device is not detected, check the wiring and try 0x76 or 0x77 according to the TP1/SDO state.

Firmware ​

Use the tool below to flash the precompiled firmware to the ESP32-C3 Dev Module directly from your browser, without installing additional software. This image is configured for the BME690 Module at I2C address 0x76, with SDA on GPIO8 and SCL on GPIO10:

ESP32 Flasher (Official API)

⚪Disconnected

Select firmware

Operation log

Instructions and Troubleshooting

For flashing problems and other troubleshooting, see the ESP Flasher Guide.

Code ​

Read Raw Sensor Data ​

The following example uses forced mode in Bosch-BME690-Library to read temperature, pressure, humidity, and gas resistance. BME69X_I2C_ADDR_LOW selects 0x76; use BME69X_I2C_ADDR_HIGH for the high address.

cpp
#include <Arduino.h>
#include <Wire.h>
#include <bme69xLibrary.h>

Bme69x bme;

void setup() {
  Serial.begin(115200);
  Wire.begin();

  bme.begin(BME69X_I2C_ADDR_LOW, Wire);
  if (bme.checkStatus() == BME69X_ERROR) {
    Serial.println("BME690 initialization failed: " + bme.statusString());
    while (true) delay(1000);
  }

  bme.setTPH();
  bme.setHeaterProf(300, 100);  // 300 °C, 100 ms
}

void loop() {
  bme69xData data;

  bme.setOpMode(BME69X_FORCED_MODE);
  delayMicroseconds(bme.getMeasDur());

  if (bme.fetchData()) {
    bme.getData(data);
    Serial.print("T=");
    Serial.print(data.temperature);
    Serial.print(" °C, P=");
    Serial.print(data.pressure);
    Serial.print(" Pa, H=");
    Serial.print(data.humidity);
    Serial.print(" %, Gas=");
    Serial.print(data.gas_resistance);
    Serial.println(" Ω");
  }
}

Read IAQ with BSEC3 ​

Open the BSEC3 library example examples/basic_config_state in Arduino IDE. Copy these three files into the sketch directory:

  • basic_config_state.ino
  • bsec_selectivity.c
  • bsec_selectivity.h

The example uses the bsec_config_state_selectivity configuration, restores a previously saved BSEC state at startup, and periodically saves a new state after IAQ accuracy reaches 3. The loadState() and saveState() functions in the example are storage placeholders: replace their bodies with EEPROM, Preferences, LittleFS, flash, or another non-volatile storage implementation before expecting state to survive a reset.

Configuration and Sample Rate

The example defaults to BSEC_SAMPLE_RATE_LP, which produces updates about every 3 seconds. The configuration in bsec_selectivity.c must match the selected sample rate and the BME690 supply voltage. If you change SAMPLE_RATE to ULP, use the matching ULP configuration and TEMP_OFFSET_ULP.

cpp
/**
 * Copyright (C) 2024 Bosch Sensortec GmbH
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

/**
 * basic_config_state.ino sketch :
 * This example illustrates loading a BSEC configuration blob and periodically
 * saving / restoring the BSEC algorithm state through user-provided storage.
 *
 * By default it targets the BME690 with the same configuration and I2C pins
 * as bme690_iaq. To target the BME688, define BSEC3_BME688 for the whole build.
 *
 * NOTE: replace the loadState()/saveState() bodies with your own non-volatile
 * storage (EEPROM, LittleFS, Preferences, flash, ...). The skeleton below does
 * not persist state across resets.
 */

#include <bsec3.h>
#include "bsec_selectivity.h"

/* Macros used */
#define SAMPLE_RATE         BSEC_SAMPLE_RATE_LP
#define STATE_SAVE_PERIOD   UINT32_C(360 * 60 * 1000) /* every 360 minutes */
#define BME6XX_ADDR          BME6XX_I2C_ADDR_LOW

/* Match the wiring verified with bme690_iaq. Set both to -1 for board defaults.
 * No LED pin is configured, since it may share a pin with the I2C bus. */
#define I2C_SDA_PIN          (8)
#define I2C_SCL_PIN          (10)

/* Buffer used to persist the algorithm state */
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE] = { 0 };
uint16_t stateUpdateCounter = 0;

/* Helper functions declarations */
void checkBsecStatus(Bsec3 bsec);
void updateBsecState(Bsec3 bsec);
bool loadState(uint8_t *state);
bool saveState(const uint8_t *state);
void newDataCallback(const bme6xxData data, const bsecOutputs outputs, Bsec3 bsec);

/* Create an object of the class Bsec3 */
Bsec3 envSensor;
bool sensorReady = false;

void setup(void)
{
    bsecSensor sensorList[] = {
            BSEC_OUTPUT_RAW_PRESSURE,
            BSEC_OUTPUT_RAW_TEMPERATURE,
            BSEC_OUTPUT_RAW_HUMIDITY,
            BSEC_OUTPUT_RAW_GAS,
            BSEC_OUTPUT_IAQ,
            BSEC_OUTPUT_STATIC_IAQ,
            BSEC_OUTPUT_CO2_EQUIVALENT,
#ifdef BSEC3_BME688
            BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
#endif
            BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
            BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
#ifndef BSEC3_BME688
            BSEC_OUTPUT_TVOC_EQUIVALENT /* Keep last: only supported at LP. */
#endif
    };
    uint8_t nSensors = ARRAY_LEN(sensorList);
#ifndef BSEC3_BME688
    if (SAMPLE_RATE != BSEC_SAMPLE_RATE_LP)
    {
        nSensors--;
    }
#endif

    Serial.begin(115200);
#if (I2C_SDA_PIN >= 0) && (I2C_SCL_PIN >= 0)
    Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
#else
    Wire.begin();
#endif
    while (!Serial) delay(10);

    if (!envSensor.begin(BME6XX_ADDR, Wire))
    {
        checkBsecStatus(envSensor);
        return;
    }

    /* Load the matching IAQ example's configuration before restoring state.
     * A valid configuration can start with 0; do not test its first byte. */
    if (!envSensor.setConfig(bsec_config_state_selectivity))
    {
        checkBsecStatus(envSensor);
        return;
    }

    /* Restore the previously saved state, if any */
    if (loadState(bsecState))
    {
        if (!envSensor.setState(bsecState))
        {
            checkBsecStatus(envSensor);
            return;
        }
    }

    if (SAMPLE_RATE == BSEC_SAMPLE_RATE_LP)
    {
        envSensor.setTemperatureOffset(TEMP_OFFSET_LP);
    }
    else if (SAMPLE_RATE == BSEC_SAMPLE_RATE_ULP)
    {
        envSensor.setTemperatureOffset(TEMP_OFFSET_ULP);
    }

    if (!envSensor.updateSubscription(sensorList, nSensors, SAMPLE_RATE))
    {
        checkBsecStatus(envSensor);
        return;
    }

    envSensor.attachCallback(newDataCallback);
    sensorReady = true;

    Serial.println("BSEC library version " + \
            String(envSensor.version.major) + "." \
            + String(envSensor.version.minor) + "." \
            + String(envSensor.version.major_bugfix) + "." \
            + String(envSensor.version.minor_bugfix));
}

void loop(void)
{
    if (!sensorReady)
    {
        delay(1000);
        return;
    }

    if (!envSensor.run())
    {
        checkBsecStatus(envSensor);
    }
}

void newDataCallback(const bme6xxData data, const bsecOutputs outputs, Bsec3 bsec)
{
    if (!outputs.nOutputs)
    {
        return;
    }

    for (uint8_t i = 0; i < outputs.nOutputs; i++)
    {
        const bsecData output = outputs.output[i];
        switch (output.sensor_id)
        {
            case BSEC_OUTPUT_RAW_TEMPERATURE:
                Serial.println("Temperature = " + String(output.signal));
                break;
            case BSEC_OUTPUT_RAW_PRESSURE:
                Serial.println("Pressure = " + String(output.signal));
                break;
            case BSEC_OUTPUT_RAW_HUMIDITY:
                Serial.println("Humidity = " + String(output.signal));
                break;
            case BSEC_OUTPUT_RAW_GAS:
                Serial.println("Gas resistance = " + String(output.signal));
                break;
            case BSEC_OUTPUT_IAQ:
                Serial.println("IAQ = " + String(output.signal) +
                               ", accuracy = " + String((int) output.accuracy));
                /* Save the state once the IAQ accuracy reaches a stable value */
                if (output.accuracy >= 3)
                {
                    updateBsecState(envSensor);
                }
                break;
            case BSEC_OUTPUT_STATIC_IAQ:
                Serial.println("Static IAQ = " + String(output.signal));
                break;
            case BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE:
                Serial.println("Compensated temperature = " + String(output.signal));
                break;
            case BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY:
                Serial.println("Compensated humidity = " + String(output.signal));
                break;
            case BSEC_OUTPUT_CO2_EQUIVALENT:
                Serial.println("CO2 Equivalent = " + String(output.signal));
                break;
            case BSEC_OUTPUT_BREATH_VOC_EQUIVALENT:
                Serial.println("bVOC equivalent = " + String(output.signal));
                break;
            case BSEC_OUTPUT_TVOC_EQUIVALENT:
                Serial.println("TVOC equivalent = " + String(output.signal));
                break;
            default:
                break;
        }
    }
}

void updateBsecState(Bsec3 bsec)
{
    bool update = false;

    if (!stateUpdateCounter || (bsec.getTimeMs() - stateUpdateCounter * (int64_t)STATE_SAVE_PERIOD) >= STATE_SAVE_PERIOD)
    {
        update = true;
        stateUpdateCounter++;
    }

    if (update)
    {
        if (!bsec.getState(bsecState))
        {
            checkBsecStatus(bsec);
            return;
        }
        saveState(bsecState);
        Serial.println("Saved BSEC state to non-volatile memory");
    }
}

/* ---- Replace the two functions below with real non-volatile storage ---- */

bool loadState(uint8_t *state)
{
    /* TODO: read BSEC_MAX_STATE_BLOB_SIZE bytes from your storage into `state`.
     * Return true only if a valid previously-saved state was found. */
    (void) state;
    return false;
}

bool saveState(const uint8_t *state)
{
    /* TODO: persist BSEC_MAX_STATE_BLOB_SIZE bytes from `state` to your storage. */
    (void) state;
    return true;
}

void checkBsecStatus(Bsec3 bsec)
{
    if (bsec.status < BSEC_OK)
    {
        Serial.println("BSEC error code : " + String(bsec.status));
    }
    else if (bsec.status > BSEC_OK)
    {
        Serial.println("BSEC warning code : " + String(bsec.status));
    }

    if (bsec.sensor.checkStatus() < BME6XX_OK)
    {
        Serial.println("BME6xx error code : " + String(bsec.sensor.checkStatus()) +
                       " (raw status = " + String(bsec.sensor.status) + ")");
    }
    else if (bsec.sensor.checkStatus() > BME6XX_OK)
    {
        Serial.println("BME6xx warning code : " + String(bsec.sensor.checkStatus()));
    }
}

This is the library's state-aware example, so it includes configuration loading, optional state restoration, periodic state saving, callback output, and status reporting. Keep bsec_selectivity.c and bsec_selectivity.h from the same example directory; do not substitute the bsec_config_selectivity files from the older IAQ example.

Sample Rate and Configuration ​

  • BSEC_SAMPLE_RATE_LP: updates about every 3 seconds and is the default in this example.
  • BSEC_SAMPLE_RATE_ULP: updates about every 300 seconds and uses less power.

The configuration must match the BME690, supply voltage, and sample rate. For BME690, BSEC_OUTPUT_TVOC_EQUIVALENT is supported only at LP. The code keeps that output at the end of the subscription list and removes it automatically when another sample rate is selected. Define BSEC3_BME688 for the whole build only when targeting a BME688.

Save the Algorithm State ​

The example calls getState() after IAQ accuracy reaches 3 and then calls saveState() every 360 minutes. Implement loadState() and saveState() with non-volatile storage so the learned baseline can be restored after a restart. BSEC_MAX_STATE_BLOB_SIZE gives the required buffer size for the installed library version.

FAQ ​

Sensor Not Found ​

  1. Check that VCC, GND, SDA, and SCL are connected correctly.
  2. Check that the controller I2C pins match the Wire.begin() settings.
  3. Try 0x76 and 0x77 according to the TP1/SDO state.
  4. Make sure Bosch-BME690-Library is installed and that the project does not include a BME688 driver macro.

updateSubscription() Returns an Error ​

Check whether the requested outputs are supported by the BME690 IAQ solution and the selected sample rate. BME690 does not support BSEC_OUTPUT_BREATH_VOC_EQUIVALENT or BSEC_OUTPUT_COMPENSATED_GAS; BSEC_OUTPUT_TVOC_EQUIVALENT supports LP only.

IAQ Does Not Stabilize ​

Keep the sensor ventilated, avoid direct heating from fingers, heaters, or the enclosure, and let the algorithm run continuously. Allow the algorithm state to rebuild after changing the installation location or environment.