// Libary
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
// Pins Setup
#define BME_SCK 13 // SCL pin of Sensor
#define BME_MISO 12 // SDO pin of Sensor
#define BME_MOSI 11 // SDA pin of Sensor
#define BME_CS 10 // CS pin of Sensor
// Setting the sea level pressure (roughly 1024-1025 hPa from BOM)
#define SEALEVELPRESSURE_HPA (1025)
// Setting up a varible to reoresent BME sensor
Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
void setup() {
// Serial Begin
Serial.begin(9600);
// If the BME is not able to start
if (!bme.begin()) {
Serial.println(F("Could not find a valid BME680 sensor, check wiring!"));
while (1);
}
// Set values to BME variable for accuracy
bme.setTemperatureOversampling(BME680_OS_2X); // Parameters accepts readings
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_2X);
// Avoid external Disturbances
bme.setIIRFilterSize(BME680_FILTER_SIZE_1);
// For Gas Sensor setup accept temp and time the heater is on for
bme.setGasHeater(320, 200); // 320 Degrees C, 200 ms
}
void loop() {
// BME680 begins reading values
unsigned long endTime = bme.beginReading();
// If the readings has not started
if (endTime == 0) {
Serial.println(F("BME Measuring Failed to Read Values..."));
return;
}
// Calling endReading & If the readings was not fully completted
if (!bme.endReading()) {
Serial.println(F("BME Measuring Failed to Finish Reading Values..."));
return;
}
// DISPLAY VALUES
Serial.print(F("Temperature = "));
Serial.print(bme.temperature);
Serial.println(F(" *C"));
Serial.print(F("Pressure = "));
Serial.print(bme.pressure / 100.0);
Serial.println(F(" hPa"));
Serial.print(F("Humidity = "));
Serial.print(bme.humidity);
Serial.println(F(" %"));
Serial.print(F("Gas = "));
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(F(" KOhms"));
}