Introduction

BME280 is an environmental sensor that integrates onboard temperature sensor, humidity sensor and barometer. The sensor is of high precision, multiple functions, and small size etc. It provides both SPI and I2C interfaces, which make it easy to make a fast prototypes. It can be widely used in environmental monitoring, story height measurement and Internet of Things (IoT) control and so on. Gravity I2C BME280 Environmental Sensor has based on BoSCH newest MEMS sensor (Micro-Electro-Mechanical System). It is very stable to compare with other kind of sensors, especially the air pressure measurement, the offset temperature coefficient is ±1.5 Pa/K, equiv. to ±12.6 cm at 1 °C temperature change. Therefore, the stable and multi-function make BME280 become a good choice in many scenes.

Specification

Board Overview

Gravity: I2C BME280 Environmental Sensor Layout

Num Label Description
1 + 3.3~5V
2 - GND
3 C SCL
4 D SDA

Tutorial

BME280 Environmental Sensor has two interface: I2C and SPI. In this section, we'll show you two examples about how to use.

Requirements

Arduino I2C Connection Diagram

Arduino I2C Connection

Arduino I2C Sample Code

 * raed_data_i2c.ino
 *
 * Download this demo to test read data from bme280, connect sensor through IIC interface
 * Data will print on your serial monitor
 *
 * Copyright   [DFRobot](http://www.dfrobot.com), 2016
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  12/03/2019
 */

#include "DFRobot_BME280.h"
#include "Wire.h"

typedef DFRobot_BME280_IIC    BME;    // ******** use abbreviations instead of full names ********

BME   bme(&Wire, 0x77);   // select TwoWire peripheral and set sensor address

#define SEA_LEVEL_PRESSURE    1015.0f

// show last sensor operate status
void printLastOperateStatus(BME::eStatus_t eStatus)
{
  switch(eStatus) {
  case BME::eStatusOK:    Serial.println("everything ok"); break;
  case BME::eStatusErr:   Serial.println("unknow error"); break;
  case BME::eStatusErrDeviceNotDetected:    Serial.println("device not detected"); break;
  case BME::eStatusErrParameter:    Serial.println("parameter error"); break;
  default: Serial.println("unknow status"); break;
  }
}

void setup()
{
  Serial.begin(115200);
  bme.reset();
  Serial.println("bme read data test");
  while(bme.begin() != BME::eStatusOK) {
    Serial.println("bme begin faild");
    printLastOperateStatus(bme.lastOperateStatus);
    delay(2000);
  }
  Serial.println("bme begin success");
  delay(100);
}

void loop()
{
  float   temp = bme.getTemperature();
  uint32_t    press = bme.getPressure();
  float   alti = bme.calAltitude(SEA_LEVEL_PRESSURE, press);
  float   humi = bme.getHumidity();

  Serial.println();
  Serial.println("======== start print ========");
  Serial.print("temperature (unit Celsius): "); Serial.println(temp);
  Serial.print("pressure (unit pa):         "); Serial.println(press);
  Serial.print("altitude (unit meter):      "); Serial.println(alti);
  Serial.print("humidity (unit percent):    "); Serial.println(humi);
  Serial.println("========  end print  ========");

  delay(1000);
}

Expected Results

Result

Arduino SPI Connection Diagram

Arduino SPI Connection

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get Gravity: I2C BME280 Environmental Sensor from DFRobot Store or DFRobot Distributor.

Turn to the Top