PCBWay Main Content Banner
ESP8266IoT Projects

IoT Based Indoor Air Quality Monitoring Using BME680 & ESP8266

BME680 Indoor Air Quality Monitoring Using ESP8266

Overview: Indoor Air Quality Monitoring using BME680

Today, in this session, we are going to build IoT Based Indoor Air Quality Monitoring Using BME680 & ESP8266. The BME680 is an environmental Digital Sensor that measures Gas (VOC) & IAQ, Pressure, Humidity, Temperature, Altitude, and using some mathematical calculations we can derive the Dew point. In this guide, you will learn to interfere BME680 sensor with the ESP8266 NodeMCU development board and program using Arduino IDE to monitor its parameters on the Blynk Application. This BME680 environmental sensor can communicate with microcontrollers using both I2C or SPI communication protocols.

By the end of this tutorial, you will be able to interface the BME680 sensor with the ESP8266 board, install the required libraries, and program the ESP8266 development board. Furthermore, we will design a blynk app dashboard to remotely monitor the BME680 sensor data from anywhere in the world using smartphones.

Components Required

These are the components required for making BME680 Indoor Air Quality Monitoring System using ESP8266.

S.NComponents NameQuantityGet Products from Amazon
1NodeMCU ESP8266 12E Board1https://amzn.to/3mTuL95
2BME680 Environmental Sensor1https://amzn.to/2R7LhXZ
3Jumper Wires4https://amzn.to/3vw9ZAt
4Breadboard1https://amzn.to/2NP2UKL

You can get all the parts for your projects at the best price on Amazon.


Introduction to BME680 Environmental Sensor

The BME680 is an Environmental sensor that has the capabilities to measure gas (VOCs), pressure, humidity, temperature, and even altitude. The gas sensor on BME680 can detect a wide range of gases, such as volatile organic compounds (VOCs). So the BME680 sensor can be used to control the indoor quality of air.

BME680 Breakout Board
BME680 Sensor Measures

As I already mentioned above, The BME680 is a five in one Environmental digital sensor that measures:

  • Gas: Volatile Organic Compounds (VOC) like ethanol and carbon monoxide
  • Temperature
  • Humidity
  • Barometric pressure &
  • Altitude
Accuracy of BME680 Sensor

The following table shows the Accuracy and operation range of the temperature, humidity, pressure, altitude, and gas sensors of the BME680 Environmental Sensor:

SensorAccuracyOperation Range
Temperature+/- 1.0ºC-40 to 85 ºC
Humidity+/- 3%0 to 100 %
Pressure+/- 1 hPa300 to 1100 hPa
Altitude+/- 1 M0 – 30,000ft
The Gas Sensor used on BME680

For this IoT Based Indoor Air Quality Monitoring Project. We have used the BME680 sensor. That includes a MOX (metal-oxide) sensor that detects VOCs in the air.

The MOX sensor is made up of a sensitive layer of the metal-oxide surface. It detects VOCs by absorbing oxygen molecules in its sensitive layer.

Basically, when the sensor is exposed to low gases, oxygen molecules react and increase conductivity across the surface. BME680 sensor provides resistance values as a raw signal. These values ​​changes because of differences in VOC concentrations:

  • Low resistance means A high concentration of VOCs
  • High resistance means Low concentration of VOCs
BME680 sensor Pinout
BME680 Environmental Sensor

The following table is the BME680 sensor Pinout table:

VCCPowers the sensor
GNDGround Pin
SCLSCL pin for I2C communication
SCK pin for SPI communication
SDASDA pin for I2C communication
SDI (MOSI) pin for SPI communication
SDOSDO (MISO) pin for SPI communication
CSChip select pin for SPI communication

Circuit Diagram: IoT & BME680 Indoor Air Quality Monitoring System

The BME680 Environmental Sensor can communicate using I2C or SPI communication protocols. So, In this IoT Based Indoor Air Quality Monitoring Using BME680 & ESP8266 Project. we will learn the wiring for both I2C and SPI communication protocol.

Following is the schematic diagram to wire the BME680 to the ESP8266 NodeMCU using the default I2C pins.

Circuit Diagram of IoT Based Indoor Air Quality Monitoring Using BME680 & ESP8266

ESP8266 with BME680 using I2C

BME680ESP8266 NodeMCU
SCLGPIO 05 (D1)
SDAGPIO 04 (D2)
VCC3.3V
GNDGND

ESP8266 with BME680 using SPI

Alternatively, you can use the SPI communication protocol instead. In that case, the following connection table will help you to wire the BME680 to the ESP8266 using the default SPI pins.

BME680ESP8266 NodeMCU
VCC3.3V
GNDGND
SCL (SCK SPI Clock)GPIO 05
SDA (SDI MOSI)GPIO 04
SDO (MISO)GPIO 12
CS (Chip Select)GPIO 15

I have assembled the circuit on breadboard but you can order a custom PCB from PCBWay.com

Interfacing BME680 with ESP8266 NodeMCU

This tutorial is sponsored by the PCBWay Company. PCBWay is quite professional in the field of PCB manufacturing. you can try their services at extremely low prices. Only $5 for 10 PCBs and $30 in total for 20 PCBs assembly. besides this, the new members also get a $5 signup bonus. That means the new users can order 10 PCBs for free.


Blynk App configuration for BME680 IAQ Monitoring

I have done many projects related to IoT with the Blynk application and designed many apps before. In this session, I am designing IoT based Indoor Air Quality Monitoring App. So, Make sure you download and install the Blynk app from Playstore/Appstore.

  • First of all, open the blynk application.
  • Click on the create a new project and enter the project name as “Indoor Air Quality“. Instead, you can type any name. You can change the name later.
  • Click on Choice Tools and select NodeMCU ESP8266.
  • Make sure the connection type is set to WIFI.
Indoor Air Quality using BME680
  • Finally, click on the create button, a verification token will be sent to your email ID, which will be used in the Program CODE.
  • Click + icon on the screen and search for the Gauge widget add 3 of them and search for the value display Widget. Add 3 of them to your Blynk App dashboard. Lastly, add a text display widget and configure them as shown in the image below. Now the application for IoT Indoor Air Quality Monitoring is ready to use.
IAQ monitor on Blynk Dashboard

Preparing Arduino IDE For BME680

Actually, We’ll program the ESP8266 board using Arduino IDE. So, make sure you have the ESP8266 add-on installed.

Basically, to compile this program we also need to install the Adafruit BME680 library and the Adafruit Unified Sensor library.

Installing the BME680 Library

To get readings from the BME680 Environmental sensor module we’ll use the Adafruit_BME680 library. Actually, following are steps to install the library in your Arduino IDE:

Installing the BME680 Library In Arduino IDE

Open your Arduino IDE and go to Sketch Include Library > and Manage Libraries. Now the Library Manager should open. Here, search for “adafruit bme680 ” on the Search box and click on install to install the library.

Installing the Adafruit_Sensor Library

Actually, to use the BME680 library, we also need to install the Adafruit_Sensor library. Follow the same steps mentioned above to install the library in your Arduino IDE:

Go to Sketch Include Library > Manage Libraries and then type “Adafruit Unified Sensor” in the search box. Scroll all the way down to find the library. Now, you click on the install button and install it.

Installing the Adafruit_Sensor Library in esp8266

Note: After installing the libraries, restart your Arduino IDE.


Program Code Explanation

Firstly, the code starts by including the required libraries: Wire.h Library to use the I2C communication protocol. SPI.h Library to use SPI communication protocol instead of I2C. Secondly, Adafruit_Sensor and Adafruit_BME680 libraries to read data from BME680 sensors. Similarly, BlynkSimpleEsp8266.h to communicate between NodeMCU ESP8266 and Blynk IoT Cloud.

Install BlynkSimpleEsp8266.h library from here: Installing BlynkSimpleEsp8266.h library on Arduino IDE

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

Initialize the BME680 sensor.

Adafruit_BME680 bme;

Define the different variables for storing sensor data like temperature, humidity, pressure, altitude, dewpoint, & gas.

float Temperature;
float Humidity;
float Pressure;
float Gas;
float Altitude;
float DewPont;

Replace the following field with your Blynk Authentication token and Wi-Fi Network credentials

char auth[] = " xxx-xxxx-xxx";
char ssid[] = "xxx-xxxx-xxx";
char pass[] = "xxx-xxxx-xxx";

Connect to Blynk cloud then Initialize the BME680 Environmental sensor.

Blynk.begin(auth, ssid, pass);
  bme.begin(0x76);

In the void BME680(), we’ll get readings from the BME680 sensor. First, tell the sensor to start reading data and store them on variables. Do some calculations and send those reading to Blynk IoT Cloud through virtual pin as defined.

Finally, After adding the following code, we can get the readings as follows:

  • bme.readTemperature: provides a temperature reading
  • bme.readPressure: provides a pressure reading
  • bme.readHumidity: provides humidity reading
  • bme.gas_resistance: provides gas resistance
  • bme.readAltitude: provides altitude value.
  • DewPointFast(Temperature, Humidity) calculates dew point.
void bme680()
{
  Temperature = bme.readTemperature();
  Blynk.virtualWrite(V1, Temperature);

  Humidity = bme.readHumidity();
  Blynk.virtualWrite(V2, Humidity);

  Pressure = bme.readPressure() / 100.0F;
  Blynk.virtualWrite(V3, Pressure);

  Altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  Blynk.virtualWrite(V4, Altitude);

  Gas = (bme.gas_resistance / 1000.0);
  Blynk.virtualWrite(V5, Gas);

  if ((Gas > 0)  && (Gas  <= 50)) {
    Blynk.virtualWrite(V6, "IAQ GOOD");
  }
  if ((Gas > 51)  && (Gas  <= 100)) {
    Blynk.virtualWrite(V6, "IAQ Average");
  }
  if ((Gas > 101)  && (Gas  <= 150)) {
    Blynk.virtualWrite(V6, "IAQ Little Bad");
  }
  if ((Gas > 151)  && (Gas  <= 200)) {
    Blynk.virtualWrite(V6, "IAQ Bad");
  }
  if ((Gas > 201)  && (Gas  <= 300)) {
    Blynk.virtualWrite(V6, "IAQ Worse");
  }
  if ((Gas > 301)  && (Gas  <= 500)) {
    Blynk.virtualWrite(V6, "IAQ Very Bad");
  }

  double DewPoint = DewPointFast(Temperature, Humidity);
  Blynk.virtualWrite(V7, DewPoint);
}

In a loop blynk.runand timer.run function is initiated. We also do some mathematical calculation for deriving dewpoint using Temperature & Humidity values.

void loop()
{
  Blynk.run();
  timer.run();
}
// DewPoint Calculation
double DewPointFast(double celsius, double Humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(Humidity * 0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}

Final Program Code for BME680 IAQ Monitoring

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme;

float Temperature;
float Humidity;
float Pressure;
float Gas;
float Altitude;
float DewPont;

BlynkTimer timer;

char auth[] = " xxx-xxxx-xxx";
char ssid[] = "xxx-xxxx-xxx";
char pass[] = "xxx-xxxx-xxx";

void setup()
{
  Blynk.begin(auth, ssid, pass);
  bme.begin(0x76);

  // 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
  
  timer.setInterval(2000L, bme680);
}

void bme680()
{
  Temperature = bme.readTemperature();
  Blynk.virtualWrite(V1, Temperature);

  Humidity = bme.readHumidity();
  Blynk.virtualWrite(V2, Humidity);

  Pressure = bme.readPressure() / 100.0F;
  Blynk.virtualWrite(V3, Pressure);

  Altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  Blynk.virtualWrite(V4, Altitude);

  Gas = (bme.gas_resistance / 1000.0);
  Blynk.virtualWrite(V5, Gas);

  if ((Gas > 0)  && (Gas  <= 50)) {
    Blynk.virtualWrite(V6, "IAQ GOOD");
  }
  if ((Gas > 51)  && (Gas  <= 100)) {
    Blynk.virtualWrite(V6, "IAQ Average");
  }
  if ((Gas > 101)  && (Gas  <= 150)) {
    Blynk.virtualWrite(V6, "IAQ Little Bad");
  }
  if ((Gas > 151)  && (Gas  <= 200)) {
    Blynk.virtualWrite(V6, "IAQ Bad");
  }
  if ((Gas > 201)  && (Gas  <= 300)) {
    Blynk.virtualWrite(V6, "IAQ Worse");
  }
  if ((Gas > 301)  && (Gas  <= 500)) {
    Blynk.virtualWrite(V6, "IAQ Very Bad");
  }

  double DewPoint = DewPointFast(Temperature, Humidity);
  Blynk.virtualWrite(V7, DewPoint);
}

void loop()
{
  Blynk.run();
  timer.run();
}
// DewPoint Calculation
double DewPointFast(double celsius, double Humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(Humidity * 0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}

Finally, copy the above program code on your Arduino IDE. Now compile the code and upload it to the NodeMCU ESP8266 board by selecting the correct board and correct port.

Open the blynk App to see the real-time data on your smartphone.


Demonstration: IoT Based Indoor Air Quality Monitoring Using BME680 & ESP8266

Run freshly configured blynk app dashboard. Now, you will get access to the cloud server with the latest BME680 sensor reading. You can access this data from any network on your smartphone from anywhere in the world.

IoT based Indoor Air Quality Monitoring on Blynk App using BME680 & ESP8266

Note: The readings are updated every second. You can customize it according to your requirements.

Video Tutorial & Guide

Wrapping Up

In this tutorial, I have shown you the IoT Based Indoor Air Quality Monitoring Using BME680 & ESP8266. This project is very helpful for monitoring our internal (home) environment wirelessly. I hope you enjoyed reading this article. If you have any questions, comments, or ideas? Let me know in the comment section below.

Recommended Readings:

Alsan Parajuli

I am a WordPress enthusiast, a hardworking and highly positive person. I always believes in practicality rather than theoretical knowledge. With my curiosity and fast learning skills, I managed to learn everything on my own. I love coding, editing, writing and rummaging around Internet. I am passionate about IoT Projects, Digital marketing, website designing, and reviewing. Moreover, I had been contributing to WordPress Biratnagar as an active member since 2018.

Related Articles

Leave a Reply

Back to top button