Home » ESP32 and BME680 sensor example

ESP32 and BME680 sensor example

by shedboy71

In this article we will connect a BME680 sensor to an ESP32 – in this case its a Lolin32 from Wemos

BME680 is an integrated environmental sensor developed specifically for mobile applications and wearables where size and low power consumption are key requirements. Expanding Bosch Sensortec’s existing family of environmental sensors, the BME680 integrates for the first time high-linearity and high-accuracy gas, pressure, humidity and temperature sensors. The gas sensor within the BME680 can detect a broad range of gases to measure air quality for personal well being.

Gases that can be detected by the BME680 include Volatile Organic Compounds (VOC) from paints (such as formaldehyde), lacquers, paint strippers, cleaning supplies, furnishings, office equipment, glues, adhesives and alcohol.

Parameter Technical data
Package dimensions 8-Pin LGA with metal
3.0 x 3.0 x 0.93 mm³
Operation range (full accuracy) Pressure: 300…1100 hPa
Humidity 0…100%
Temperature: -40…85°C
Supply voltage VDDIO
Supply voltage VDD
1.2 … 3.6 V
1.71 … 3.6 V
Interface I²C and SPI
Average current consumption
(1Hz data refresh rate)
2.1 µA at 1 Hz humidity and temperature
3.1 µA at 1 Hz pressure and temperature
3.7 µA at 1 Hz humidity, pressure and temperature 0.09‒12 mA for p/h/T/gas depending on operation mode
Average current consumption in sleep mode 0.15 μA
Gas sensor
Response time (τ 33-63%)
Sensor-to-sensor deviation
Power consumption
Output data processing
< 1 s (for new sensors)
+/- 15% +/- 15
< 0.1 mA in ultra-low power mode
direct output of IAQ: Index for Air Quality
Humidity sensor
Response time (τ0-63%)
Accuracy tolerance
Hysteresis
8 s
± 3 % relative humidity
≤ 1.5 % relative humidity
Pressure sensor
RMS Noise
Sensitivity Error
Temperature coefficient offset
0.12 Pa (equiv. to 1.7 cm)
± 0.25 % (equiv. to 1 m at 400 m height change)
±1.3 Pa/K (equiv. to ±10.9 cm at 1°C temperature change)

 

Parts List

Name Link
ESP32
BME680
Connecting cables

Schematic

We use the I2C connection for the sensor, that's 22 and 21 on the Lolin32

esp32 and bme680

esp32 and bme680

Code

You will need to import the adafruit sensor and bme680 libraries – you can add these using the library manager

My particular sensor used address 0x76, the default is 0x77 so you may have to change this line from if (!bme.begin(0x76)) to if (!bme.begin())

 

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"


#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme; // I2C

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println(F("BME680 test"));

  if (!bme.begin(0x76)) 
  {
    Serial.println("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() 
{
  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");

  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.println();
  delay(2000);
}

 

Output

Open the serial monitor and you will see something like this

Temperature = 23.26 *C
Pressure = 997.89 hPa
Humidity = 40.41 %
Gas = 166.67 KOhms
Approx. Altitude = 128.67 m

Temperature = 23.26 *C
Pressure = 997.89 hPa
Humidity = 40.43 %
Gas = 170.74 KOhms
Approx. Altitude = 128.84 m

Temperature = 23.38 *C
Pressure = 997.89 hPa
Humidity = 40.38 %
Gas = 176.13 KOhms
Approx. Altitude = 128.51 m

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.