ESP32: BME680 Environmental Sensor using Arduino IDE (Gas, Pressure, Humidity, Temperature)
Use the BME680 sensor module with ESP32 board to measure gas, pressure, temperature, humidity using Arduino IDE. It uses I2C or SPI communication protocol.
- Suitable forB.Tech/Diploma IoT/ESP32 students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
The BME680 is an environmental digital sensor that measures gas, pressure, humidity and temperature. In this guide you’ll learn how to use the BME680 sensor module with the ESP32 board using Arduino IDE. The sensor communicates with a microcontroller using I2C or SPI communication protocols.
You’ll learn how to wire the sensor to the ESP32 board, install the required libraries, use a simple sketch to display the sensor readings in the Serial Monitor and build a web server to monitor your sensor remotely.
Introducing BME680 Environmental Sensor Module
The BME680 is an environmental sensor that combines gas, pressure, humidity and temperature sensors. The gas sensor can detect a broad range of gases like volatile organic compounds (VOC). For this reason, the BME680 can be used in indoor air quality control.
BME680 Measurements
The BME680 is a 4-in-1 digital sensor that measures:
Temperature
Humidity
Barometric pressure
Gas: Volatile Organic Compounds (VOC) like ethanol and carbon monoxide
Gas Sensor
The BME680 contains a MOX (Metal-oxide) sensor that detects VOCs in the air. This sensor gives you a qualitative idea of the
sum of VOCs/contaminants
in the surrounding air –
it is not specific
for a specific gas molecule.
MOX sensors are composed of a metal-oxide surface, a sensing chip to measure changes in conductivity, and a heater. It detects VOCs by adsorption of oxygen molecules on its sensitive layer. The BME680 reacts to most VOCs polluting indoor air (except CO2).
When the sensor comes into contact with the reducing gases, the oxygen molecules react and increase the conductivity across the surface. As a raw signal, the BME680 outputs resistance values. These values change due to variations in VOC concentrations:
Higher
Lower
resistance
Lower
Higher
resistance
The reactions that occur on the sensor surface (thus, the resistance) are influenced by parameters other than VOC concentration like temperature and humidity.
Relevant Information Regarding Gas Sensor
The gas sensor gives you a qualitative idea of VOCs gasses in the surrounding air. So, you can get trends, compare your results and see if the air quality is increasing or decreasing. To get precise measurements, you need to calibrate the sensor against knows sources and build a calibration curve.
When you first get the sensor, it is recommended to run it for 48 hours after start collecting “real” data. After that, it is also recommend to run the sensor for 30 minutes before getting a gas reading.
BME680 Accuracy
Here’s the accuracy of the temperature, humidity and pressure sensors of the BME680:
Sensor
Accuracy
Temperature
+/- 1.0ºC
Humidity
+/- 3%
Pressure
+/- 1 hPa
BME680 Operation Range
The following table shows the operation range for the temperature, humidity and pressure sensors for the BME680.
Sensor
Operation
Range
Temperature
-40 to 85 ºC
Humidity
0 to 100 %
Pressure
300 to 1100 hPa
BME680 Pinout
Here’s the BME680 Pinout:
VCC
Powers the sensor
GND
Common GND
SCL
SCL pin for I2C communication
SCK pin for SPI communication
SDA
SDA pin for I2C communication
SDI (MOSI) pin for SPI communication
SDO
SDO (MISO) pin for SPI communication
CS
Chip select pin for SPI communication
BME680 Interface
The BME680 supports I2C and SPI Interfaces.
BME680 I2C
To use I2C communication protocol, use the following pins:
BME680
ESP32
SCL
GPIO22
SDA
GPIO 21
GPIO 22
(SCL) and
GPIO 21
(SDA) are the default
ESP32 I2C pins
. You can use other pins as long as you set them properly on code.
Recommended reading:
ESP32 I2C Communication: Set Pins, Multiple Bus Interfaces and Peripherals (Arduino IDE)
BME680 SPI
To use SPI communication protocol, use the following pins:
BME680
ESP32
SCL (SCK SPI Clock)
GPIO 18
SDA (SDI MOSI)
GPIO 23
SDO (MISO)
GPIO 19
CS (Chip Select)
GPIO 5
These are the default ESP32 SPI pins. You can use other pins as long as you set them properly in the code.
Parts Required
To complete this tutorial you need the following parts:
BME680 sensor module
ESP32
(read
Best ESP32 development boards
)
Breadboard
Jumper wires
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Schematic – ESP32 with BME680
The BME680 can communicate using I2C or SPI communication protocols.
ESP32 with BME680 using I2C
Follow the next schematic diagram to wire the BME680 to the ESP32 using the default I2C pins.
ESP32 with BME680 using SPI
Alternatively, you may want to use SPI communication protocol instead. In that case, follow the next schematic diagram to wire the BME680 to the ESP32 using the default SPI pins.
Recommended reading:
ESP32 Pinout Reference: Which GPIO pins should you use?
Preparing Arduino IDE
We’ll program the ESP32 board using Arduino IDE. So, make sure you have the ESP32 add-on installed. Follow the next tutorial:
Install the ESP32 Board in Arduino IDE
You also need to install the Adafruit BME680 library and the Adafruit Unified Sensor library.
Installing the BME680 Library
To get readings from the BME680 sensor module we’ll use the
Adafruit_BME680 library
. Follow the next steps to install the library in your Arduino IDE:
Open your Arduino IDE and go to
Sketch
>
Include Library
>
Manage Libraries
. The Library Manager should open.
Search for “
adafruit bme680
” on the Search box and install the library.
Installing the Adafruit_Sensor Library
To use the BME680 library, you also need to install the
Adafruit_Sensor library
. Follow the next steps to install the library in your Arduino IDE:
Go to
Sketch
>
Include Library
>
Manage Libraries
and type “
Adafruit Unified Sensor
” in the search box. Scroll all the way down to find the library and install it.
After installing the libraries, restart your Arduino IDE.
Code – Reading BME680 Gas, Pressure, Humidity and Temperature
To read gas, pressure, temperature, and humidity we’ll use a sketch example from the library.
After installing the BME680 library, and the Adafruit_Sensor library, open the Arduino IDE and, go to
File
>
Examples
>
Adafruit BME680 Library
>
bme680async
/***
Read Our Complete Guide: https://ajvikalabs.com/esp32-bme680-sensor-arduino/
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 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/
#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(115200);
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.pri
You’ll learn how to wire the sensor to the ESP32 board, install the required libraries, use a simple sketch to display the sensor readings in the Serial Monitor and build a web server to monitor your sensor remotely.
Introducing BME680 Environmental Sensor Module
The BME680 is an environmental sensor that combines gas, pressure, humidity and temperature sensors. The gas sensor can detect a broad range of gases like volatile organic compounds (VOC). For this reason, the BME680 can be used in indoor air quality control.
BME680 Measurements
The BME680 is a 4-in-1 digital sensor that measures:
Temperature
Humidity
Barometric pressure
Gas: Volatile Organic Compounds (VOC) like ethanol and carbon monoxide
Gas Sensor
The BME680 contains a MOX (Metal-oxide) sensor that detects VOCs in the air. This sensor gives you a qualitative idea of the
sum of VOCs/contaminants
in the surrounding air –
it is not specific
for a specific gas molecule.
MOX sensors are composed of a metal-oxide surface, a sensing chip to measure changes in conductivity, and a heater. It detects VOCs by adsorption of oxygen molecules on its sensitive layer. The BME680 reacts to most VOCs polluting indoor air (except CO2).
When the sensor comes into contact with the reducing gases, the oxygen molecules react and increase the conductivity across the surface. As a raw signal, the BME680 outputs resistance values. These values change due to variations in VOC concentrations:
Higher
Lower
resistance
Lower
Higher
resistance
The reactions that occur on the sensor surface (thus, the resistance) are influenced by parameters other than VOC concentration like temperature and humidity.
Relevant Information Regarding Gas Sensor
The gas sensor gives you a qualitative idea of VOCs gasses in the surrounding air. So, you can get trends, compare your results and see if the air quality is increasing or decreasing. To get precise measurements, you need to calibrate the sensor against knows sources and build a calibration curve.
When you first get the sensor, it is recommended to run it for 48 hours after start collecting “real” data. After that, it is also recommend to run the sensor for 30 minutes before getting a gas reading.
BME680 Accuracy
Here’s the accuracy of the temperature, humidity and pressure sensors of the BME680:
Sensor
Accuracy
Temperature
+/- 1.0ºC
Humidity
+/- 3%
Pressure
+/- 1 hPa
BME680 Operation Range
The following table shows the operation range for the temperature, humidity and pressure sensors for the BME680.
Sensor
Operation
Range
Temperature
-40 to 85 ºC
Humidity
0 to 100 %
Pressure
300 to 1100 hPa
BME680 Pinout
Here’s the BME680 Pinout:
VCC
Powers the sensor
GND
Common GND
SCL
SCL pin for I2C communication
SCK pin for SPI communication
SDA
SDA pin for I2C communication
SDI (MOSI) pin for SPI communication
SDO
SDO (MISO) pin for SPI communication
CS
Chip select pin for SPI communication
BME680 Interface
The BME680 supports I2C and SPI Interfaces.
BME680 I2C
To use I2C communication protocol, use the following pins:
BME680
ESP32
SCL
GPIO22
SDA
GPIO 21
GPIO 22
(SCL) and
GPIO 21
(SDA) are the default
ESP32 I2C pins
. You can use other pins as long as you set them properly on code.
Recommended reading:
ESP32 I2C Communication: Set Pins, Multiple Bus Interfaces and Peripherals (Arduino IDE)
BME680 SPI
To use SPI communication protocol, use the following pins:
BME680
ESP32
SCL (SCK SPI Clock)
GPIO 18
SDA (SDI MOSI)
GPIO 23
SDO (MISO)
GPIO 19
CS (Chip Select)
GPIO 5
These are the default ESP32 SPI pins. You can use other pins as long as you set them properly in the code.
Parts Required
To complete this tutorial you need the following parts:
BME680 sensor module
ESP32
(read
Best ESP32 development boards
)
Breadboard
Jumper wires
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Schematic – ESP32 with BME680
The BME680 can communicate using I2C or SPI communication protocols.
ESP32 with BME680 using I2C
Follow the next schematic diagram to wire the BME680 to the ESP32 using the default I2C pins.
ESP32 with BME680 using SPI
Alternatively, you may want to use SPI communication protocol instead. In that case, follow the next schematic diagram to wire the BME680 to the ESP32 using the default SPI pins.
Recommended reading:
ESP32 Pinout Reference: Which GPIO pins should you use?
Preparing Arduino IDE
We’ll program the ESP32 board using Arduino IDE. So, make sure you have the ESP32 add-on installed. Follow the next tutorial:
Install the ESP32 Board in Arduino IDE
You also need to install the Adafruit BME680 library and the Adafruit Unified Sensor library.
Installing the BME680 Library
To get readings from the BME680 sensor module we’ll use the
Adafruit_BME680 library
. Follow the next steps to install the library in your Arduino IDE:
Open your Arduino IDE and go to
Sketch
>
Include Library
>
Manage Libraries
. The Library Manager should open.
Search for “
adafruit bme680
” on the Search box and install the library.
Installing the Adafruit_Sensor Library
To use the BME680 library, you also need to install the
Adafruit_Sensor library
. Follow the next steps to install the library in your Arduino IDE:
Go to
Sketch
>
Include Library
>
Manage Libraries
and type “
Adafruit Unified Sensor
” in the search box. Scroll all the way down to find the library and install it.
After installing the libraries, restart your Arduino IDE.
Code – Reading BME680 Gas, Pressure, Humidity and Temperature
To read gas, pressure, temperature, and humidity we’ll use a sketch example from the library.
After installing the BME680 library, and the Adafruit_Sensor library, open the Arduino IDE and, go to
File
>
Examples
>
Adafruit BME680 Library
>
bme680async
/***
Read Our Complete Guide: https://ajvikalabs.com/esp32-bme680-sensor-arduino/
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 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/
#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(115200);
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.pri
Technologies used
Hardware components
- ESP32
- Arduino
Software & tools
- Arduino IDE
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.