ESP32 BME688 Environmental Sensor
The BME688 is a compact environmental sensor that measures temperature, humidity, barometric pressure, and gas concentrations. With integrated AI capabilities, it can be trained for specific gas detection applications, making it suitable for indoor air quality monitoring, smart home devices, and various IoT applications.
🔗 Quick Links
ℹ️ About BME688 Environmental Sensor
The BME688, developed by Bosch Sensortec, is a multi-functional environmental sensor that integrates temperature, humidity, barometric pressure, and gas sensing. It is the first gas sensor with AI capabilities, enabling customized gas scanning and detection of volatile organic compounds (VOCs) and volatile sulfur compounds (VSCs).
⚡ Key Features #
- Multi-Sensor Integration – Measures temperature, humidity, pressure, and gas composition.
- AI-Powered Gas Detection – Identifies VOCs and VSCs for advanced air quality analysis.
- I²C & SPI Communication – Easily interfaces with ESP32, Arduino, and other microcontrollers.
- Compact & Low Power – Ideal for smart home, industrial, and wearable applications.
With its advanced sensing and AI-driven gas detection, the BME688 is perfect for air quality monitoring, environmental control, and smart IoT applications. 🚀
🔗 Learn more about the BME688 sensor.
⚙️ BME688 Sensor Technical Specifications
Below you can see the BME688 Environmental Sensor Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.
- Type: environment
- Protocol: I2C/SPI
- Interface: I²C (up to 3.4 MHz) / SPI (up to 10 MHz)
- Pressure Range: 300 hPa to 1100 hPa
- Temperature Range: -40°C to +85°C
- Humidity Range: 0% to 100% r.H.
- Operating Voltage: 1.71V to 3.6V
- Power Consumption: 2.1 µA at 1 Hz humidity and temperature; 3.7 µA at 1 Hz humidity, pressure, and temperature; 0.9 mA in low power gas scanning mode
- Gas Sensor: Detects VOCs, VSCs, CO, and hydrogen in the ppb range
- Dimensions: 3.0 mm × 3.0 mm × 0.93 mm
- Weight: Approximately 1.5 mg
🔌 BME688 Sensor Pinout
Below you can see the pinout for the BME688 Environmental Sensor. The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32!
The BME688 module includes the following pins: VIN
: Power supply input (1.71V to 3.6V). GND
: Ground pin. SDA/SDI
: Serial Data pin for I²C or SPI communication. SCL/SCK
: Serial Clock pin for I²C or SPI communication. CS
: Chip Select for SPI communication (connect to GND for I²C mode). SDO
: Serial Data Out for SPI communication (optional in I²C mode).
🧵 BME688 Wiring with ESP32
Below you can see the wiring for the BME688 Environmental Sensor with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.
To interface the BME688 module with an ESP32 using I²C: VIN
: Connect to 3.3V on the ESP32. GND
: Connect to GND on the ESP32. SDA/SDI
: Connect to GPIO21 (default SDA). SCL/SCK
: Connect to GPIO22 (default SCL). CS
: Connect to GND to select I²C mode.
🛠️ BME688 Environmental Sensor Troubleshooting
This guide outlines a systematic approach to troubleshoot and resolve common problems with the . Start by confirming that the hardware connections are correct, as wiring mistakes are the most frequent cause of issues. If you are sure the connections are correct, follow the below steps to debug common issues.
💻 Library Not Found Error
Issue: The Arduino IDE cannot locate the required BME688 library.
Solution: Ensure that the Adafruit BME680 library is installed via the Arduino Library Manager. Restart the Arduino IDE after installation. Note that the BME688 is compatible with the BME680 library.
❌ Sensor Initialization Failure
Issue: The BME688 sensor fails to initialize, displaying an error message such as Could not find a valid BME680 sensor, check wiring!
.
Solution: Verify that all wiring connections are correct and that the sensor is receiving appropriate power. Use an I²C scanner to confirm the sensor's address.
⚠️ Incorrect or Inconsistent Readings
Issue: The sensor provides inaccurate or fluctuating temperature, humidity, or gas readings.
Solution: Ensure that the sensor is not exposed to rapid environmental changes or placed near heat sources. Allow the sensor to stabilize after power-up, as recommended by Bosch Sensortec. Calibration may be necessary for precise gas measurements.
💻 Code Examples
Below you can find code examples of BME688 Environmental Sensor with ESP32 in several frameworks:
If you encounter issues while using the BME688 Environmental Sensor, check the Common Issues Troubleshooting Guide.

ESP32 BME688 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the BME688 Environmental Sensor:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme;
void setup() {
Serial.begin(115200);
if (!bme.begin()) {
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}
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() {
if (!bme.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
Serial.print("Temperature = ");
Serial.print(bme.temperature);
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.pressure / 100.0);
Serial.println(" hPa");
Serial.print("Humidity = ");
Serial.print(bme.humidity);
Serial.println(" %");
Serial.print("Gas = ");
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(" KOhms");
delay(2000);
}
This Arduino code initializes the BME688 sensor using the Adafruit BME680 library, which is compatible with the BME688. The sensor is configured for temperature, humidity, pressure, and gas readings with specific oversampling and filtering settings. The gas heater is set to 320°C for 150 milliseconds to ensure accurate detection of volatile organic compounds (VOCs) and other gases. The sensor data is read in the loop function and printed to the Serial Monitor every two seconds.
Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP32 BME688 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
If you're using ESP-IDF to work with the BME688 Environmental Sensor, here's how you can set it up and read data from the sensor. Fill in this code in the main
ESP-IDF file:
#include "bme688.h"
#include "esp_log.h"
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_FREQ_HZ 100000
#define BME688_ADDR 0x76
static const char *TAG = "BME688";
void app_main() {
ESP_LOGI(TAG, "Initializing BME688...");
bme688_dev dev;
bme688_init(&dev, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO, I2C_MASTER_FREQ_HZ, BME688_ADDR);
while (1) {
bme688_data data;
bme688_read(&dev, &data);
ESP_LOGI(TAG, "Temperature: %.2f°C", data.temperature);
ESP_LOGI(TAG, "Pressure: %.2f hPa", data.pressure);
ESP_LOGI(TAG, "Humidity: %.2f %%", data.humidity);
ESP_LOGI(TAG, "Gas Resistance: %.2f KOhms", data.gas_resistance / 1000.0);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
This ESP-IDF code configures the ESP32 to interface with the BME688 sensor over I²C. The bme688_init
function initializes the sensor, and bme688_read
fetches temperature, humidity, pressure, and gas resistance readings, which are logged to the console every two seconds.
Update the I2C pins (I2C_MASTER_SDA_IO
and I2C_MASTER_SCL_IO
) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.

ESP32 BME688 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the BME688 Environmental Sensor
sensor:
- platform: bme680
temperature:
name: "BME688 Temperature"
pressure:
name: "BME688 Pressure"
humidity:
name: "BME688 Humidity"
gas_resistance:
name: "BME688 Gas Resistance"
address: 0x76
This ESPHome configuration integrates the BME688 sensor, allowing it to report temperature, pressure, humidity, and gas resistance values. The default I²C address of 0x76
is used.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.

ESP32 BME688 PlatformIO Code Example
For PlatformIO, make sure to configure the platformio.ini
file with the appropriate environment and libraries, and then proceed with the code.
Configure platformio.ini
First, your platformio.ini
should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit BME680 Library
wire
monitor_speed = 115200
ESP32 BME688 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the BME688 Environmental Sensor:
#include <Wire.h>
#include "Adafruit_BME680.h"
Adafruit_BME680 bme;
void setup() {
Serial.begin(115200);
if (!bme.begin()) {
Serial.println("Could not find a valid BME688 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature: ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure: ");
Serial.print(bme.readPressure() / 100.0);
Serial.println(" hPa");
Serial.print("Humidity: ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.print("Gas Resistance: ");
Serial.print(bme.readGas() / 1000.0);
Serial.println(" KOhms");
delay(2000);
}
This PlatformIO code configures the BME688 sensor using the Adafruit BME680 library. It reads and prints temperature, pressure, humidity, and gas resistance values to the Serial Monitor every two seconds.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.
Conclusion
We went through technical specifications of BME688 Environmental Sensor, its pinout, connection with ESP32 and BME688 Environmental Sensor code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.