Example Code for Arduino-Data Reading(without IAQ)

Last revision 2026/01/21

Function: read data from BME680 sensor and serial printing(without IAQ).

Hardware Preparation

  • DFRduino UNO R3 (or similar) x 1
  • BME680 Environmental Sensor module x1
  • 4PIN Connector x1

Software Preparation

Wiring Diagram

  • This product supports both IIC and SPI wiring connector. Please select suitable connector according to the wiring. There is connection diagram below for your reference.
  • I2C wiring connector is recommended, since it is plug & play and easy to use.
  • When using SPI connector, then you should use 3.3V controller(Both Power and IO port should be 3.3V).

I2C Connection: please pay attention to wiring order, VCC to Power, GND to Ground.

Connection Diagram

Sample Code

Download and install the BME680 Library. This sample code is based on IIC connector. For SPI Sample code, Please check file: DFRobot_BME680_SPI.ino in the library file. Since same functions can be realized in both way, we only provide you with I2C sample code. Calibration is needed for more accurate altitude measurement. Please fill in the sample code with correct local altitude value: seaLevel = bme.readSeaLevel(your correct local altitude value).

/*
       file DFRobot_BME680_I2C.ino

       @ https://github.com/DFRobot/DFRobot_BME680

       connect bme680 I2C interface with your board (please reference board compatibility)

       Temprature, Humidity, pressure, altitude, calibrate altitude and gas resistance data will print on serial window.

       Copyright   [DFRobot](http://www.dfrobot.com), 2016
       Copyright   GNU Lesser General Public License

       version  V1.0
       date  2017-12-7
*/

#include "DFRobot_BME680_I2C.h"
#include "Wire.h"

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

DFRobot_BME680_I2C bme(0x76);  //0x77 I2C address

float seaLevel;
void setup()
{
  uint8_t rslt = 1;
  Serial.begin(9600);
  while (!Serial);
  delay(1000);
  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
}

void loop()
{
  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

Result 1

Was this article helpful?

TOP