Adafruit BME680 + Arduino UNO: a Tutorial

by AustinS89 in Circuits > Arduino

2944 Views, 2 Favorites, 0 Comments

Adafruit BME680 + Arduino UNO: a Tutorial

BME680_tutorial.png

I'd like to show everyone how they can get started using the Adafruit BME680 with the Arduino UNO. The BME680 is a great board for collecting sensor measurements including temperature, humidity, barometric pressure, and VOC gas.

Before getting started, I've attached a video that shows the circuit working, and also gives a high level walk through of the steps I'm going to discuss here.

I'd also like to mention that the circuit diagram and code in this tutorial were built using Cirkit Designer. I've uploaded the Cirkit Designer circuit project here so you can download and use the circuit design yourself.

Video Demo

Tutorial for connecting Adafruit BME680 to Arduino UNO

Here's a video demo of the working circuit, as well as a high level summary of the steps discussed here. Feel free to skip over or come back to the video after reading the remaining steps.

Parts

For this tutorial, we'll need the following parts:

Adafruit BME680: Digi-Key link

Arduino UNO: Digi-Key link

Wiring

BME680_tutorial.png

We can see how to connect the Arduino to the BME680 in the circuit diagram generated with Cirkit Designer, which is a great tool for circuit design and diagramming.

BME680 <---> Arduino Uno

  • Vin <---> 5V
  • GND <---> GND
  • SCK <---> A5
  • SDI <---> A4

Also make sure to connect your Arduino UNO to your computer via USB.

Code

Now it's time to write some code for the Arduino!

The following sketch will collect sensor measurements from the BME680 and print them to the Serial Monitor.

  1. For this step, you'll need to have the Arduino IDE installed.
  2. Next, copy and paste the following code into a new Sketch file inside the Arduino IDE.
  3. Make sure to install the Adafruit BME680 Library inside the Arduino IDE, by selecting Tools -> Manage Libraries and searching for the Adafruit BME680 library.
  4. Select Upload to compile and upload this sketch to the Arduino UNO.
  5. Open the Serial Monitor via Tools -> Serial Monitor
  6. Make sure that baud is set to 9600
  7. You should now see measurements displayed in the console, which means everything is working!

/**
 * This example demonstrates how to collect basic measurements from the Adafruit BME680
 * board, including temperature, pressure, humidity, gas resistance, and altitude.
 * In this example, sensor measurements are printed out to the Arduino serial console,
 * which can be accessed within the Arduino IDE via (Tools -> Serial Monitor).
 * 
 * - If you are using the Arduino IDE to compile this code, make sure to first install the
 * Adafruit BME680 Library through the Arduino library manager.
 * - When you open the serial monitor to view measurements from the BME680 board, make sure
 * that you select 9600 baud so that the serial monitor can receive data from the Arduino.
 *
 * Originally written by Limor Fried & Kevin Townsend from Adafruit Industries.
 */

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

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#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(9600);
  while (!Serial);
  Serial.println(F("BME680 test"));

  if (!bme.begin()) {
    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);
}