Example Code for Arduino-Reading Data Without IAQ

Last revision 2025/12/17

This article provides a comprehensive guide on using Arduino with the BME688 sensor to read environmental data, excluding IAQ. It includes hardware and software preparation, wiring diagrams for I2C and SPI interfaces, and sample code for reading temperature, humidity, pressure, and gas resistance data, along with altitude calibration instructions.

Hardware Preparation

Software Preparation

Wiring Diagram

  • This product supports I2C interface and SPI interface. When using this product, please select the corresponding wiring method according to the communication interface selected. Refer to the following diagram for the connection method.
  • I2C interface is recommended for plug-and-play, easy to use. It is recommended to use the I2C interface, which is easy to use.
  • If SPI interface is used, the module will be powered by 3.3V.

I2C diagram

Be sure to pay attention to the wire sequence, VCC to 5V, GND grounded

Other Preparation Work

  • Please install the Arduino library files first. DFRobot_BME68x
  • This sample code uses I2C interface. For SPI interface sample code, please go to the library file to find DFRobot_BME68x_SPI.ino file, due to the same function, we do not show the code here.
  • Calibration is required for accurate altitude measurement. Before uploading the code, please fill in the altitude value of your region into the statement in the sample code: seaLevel = bme.readSeaLevel(altitude value of your region);

Sample Code

/*!
 * @file DFRobot_BME68x_I2C.ino
 * @brief connect bme68x I2C interface with your board (please reference board compatibility)
 * @n Temprature, Humidity, pressure, altitude, calibrate altitude and gas resistance data will print on serial window.
 *
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license     The MIT License (MIT)
 * @author [Frank]([email protected])
 * @maintainer [GDuang]([email protected])
 * @version  V2.0
 * @date  2024-04-25
 * @url https://github.com/DFRobot/DFRobot_BME68x
 */

#include "DFRobot_BME68x_I2C.h"
#include "Wire.h"

/*use an accurate altitude to calibrate sea level air pressure*/
#define CALIBRATE_PRESSURE

DFRobot_BME68x_I2C bme(0x77);  //0x77 I2C address

float seaLevel; 
void setup()
{
  uint8_t rslt = 1;
  Serial.begin(9600);
  while(!Serial);
  delay(5000);
  Serial.println();
  while(rslt != 0) {
    rslt = bme.begin();
    if(rslt != 0) {
      Serial.println("bme begin failure");
      delay(2000);
    }
  }
  Serial.println("bme begin successful");
  #ifdef CALIBRATE_PRESSURE
  bme.startConvert();
  delay(1000);
  bme.update();
  /*You can use an accurate altitude to calibrate sea level air pressure. 
   *And then use this calibrated sea level pressure as a reference to obtain the calibrated altitude.
   *In this case,525.0m is chendu accurate altitude.
   */
  seaLevel = bme.readSeaLevel(525.0);
  Serial.print("seaLevel :");
  Serial.println(seaLevel);
  #endif

  // At initialization, the default heating layer target temperature is 320 and the duration is 150ms
  bool res = bme.setGasHeater(360, 100);
  
  Serial.print("Set the target temperature of the heating layer and the heating time: ");
  if(res == true){
    Serial.println("set successful!");
  }else{
    Serial.println("set failure!");
  }
}

void loop()
{
  bme.setGasHeater(320, 100);
  delay(30);
  bme.startConvert();
  delay(1000);
  bme.update();
  Serial.println();
  Serial.print("temperature(C) :");
  Serial.println(bme.readTemperature() / 100, 2);
  Serial.print("pressure(Pa) :");
  Serial.println(bme.readPressure());
  Serial.print("humidity(%rh) :");
  Serial.println(bme.readHumidity() / 1000, 2);
  Serial.print("gas resistance(ohm) :");
  Serial.println(bme.readGasResistance());
  Serial.print("altitude(m) :");
  Serial.println(bme.readAltitude());
  #ifdef CALIBRATE_PRESSURE
  Serial.print("calibrated altitude(m) :");
  Serial.println(bme.readCalibratedAltitude(seaLevel));
  #endif
}

Result

Additional Information

For SPI interface sample code, please go to the DFRobot_BME68x library file to find DFRobot_BME68x_SPI.ino file.

Was this article helpful?

TOP