Electorials Electronics
Published © GPL3+

Project 018: Arduino BME280 Environmental Sensor Project

A beginner project utilising an Arduino and a BME280 sensor capable of giving you 4 environmental readings.

BeginnerProtip12 minutes3,594
Project 018: Arduino BME280 Environmental Sensor Project

Things used in this project

Hardware components

Gravity: I2C BME280 Environmental Sensor
DFRobot Gravity: I2C BME280 Environmental Sensor
×1
DFRobot Gravity 4-pin i2c/UART Sensor Wire
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
You could use any other Arduino board as well. The Seeeduino v4.2 is used in this example.
×1
Jumper wires (generic)
Jumper wires (generic)
4 Male to Male Jumper Wires.
×4
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
Depends on the Arduino.
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1

Story

Read more

Schematics

Circuit Diagram

Schematics

Code

Arduino BME280 Environmental Sensor Project Code

C/C++
#include "DFRobot_BME280.h"
#include "Wire.h"

typedef DFRobot_BME280_IIC    BME;    // 
BME   bme(&Wire, 0x77);   // select TwoWire peripheral and set sensor address
#define SEA_LEVEL_PRESSURE    1015.0f

void printLastOperateStatus(BME::eStatus_t eStatus) // show last sensor operate status
{
  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);
}

Code Library

Please download the code library from the link given before compiling and uploading the program: https://github.com/DFRobot/DFRobot_BME280

Credits

Electorials Electronics

Electorials Electronics

76 projects • 26 followers
I'm an electronic hobbyist interested in anything, from Arduino to drones. I plan to educate people with the content on my website.

Comments