Language: EN

sensor-ambiental-arduino-bme280

Environmental Sensor with Arduino and BME280

What is a BME280?

The BME280 sensor is an environmental sensor from the manufacturer Bosch Sensortech that combines a thermometer, barometer, and hygrometer in a single device that we can use with a processor like Arduino.

The BME280 is based on the BMP280 sensor, which as we saw in this post is a thermometer and barometer, but adds the functions of measuring humidity.

The characteristics in terms of temperature and atmospheric pressure measurement remain the same as the BMP280, which we remember is a temperature range of -40 to +85 °C with an accuracy of ±1 °C and a resolution of 0.01 °C, and for pressure 300-1100 hPa, accuracy of ±1 Pa, and resolution of 0.18 Pa.

Regarding its behavior as a hygrometer, the BME280 has a relative humidity measurement range of 0 to 100%, with an accuracy of ±3% Pa and a resolution of 0.008%.

Communication with the module can be done via I2C (up to 3.4 MHz) or SPI (up to 10 MHz), making it very easy to connect to a processor like Arduino.

The BME280 has an operating voltage of 3V3, although some modules have level adaptation for power and signals to be compatible with 5V.

Price

The BME is a fairly inexpensive sensor, considering that it has temperature, humidity, and pressure measurement in the same device. The price is usually lower in 3V3 modules, compared to those that allow both 3V3/5V.

We can find a compatible 3V3/5V BME280 for around €2.40, from international sellers on eBay or AliExpress.

arduino-bmp280-bme280-componente

Be careful not to buy a BMP280, they are physically identical. They are much cheaper, but do not have humidity measurement.

Assembly diagram

The connection is simple, we simply power the module from Arduino using GND and 5V and connect the SDA and SCL pins of Arduino with the corresponding pins of the BMP280.

arduino-bmp280-bme280-esquema

While the connection seen from the Arduino side would look like this.

arduino-bmp280-bme280-conexion

In Arduino Uno, Nano, and Mini Pro, SDA is pin A4 and SCK is pin A5. For other Arduino models, check the corresponding pinout diagram.

Verify that your board is compatible with 5V before connecting it to Arduino. If not, you will have to use a logic level adapter.

Code examples

To read the BME280, we will use the library developed by Adafruit, available at https://github.com/adafruit/Adafruit_BME280_Library.

The library provides code examples, which it is advisable to review. The following examples, for example, are modifications based on those available in the library.

Get the values of temperature, humidity, and pressure

In this example, the raw measurement values of temperature, humidity, and pressure are obtained and displayed on the screen. These values are useful, for example, for creating a weather station.

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme; // use I2C interface
Adafruit_Sensor *bme_temp = bme.getTemperatureSensor();
Adafruit_Sensor *bme_pressure = bme.getPressureSensor();
Adafruit_Sensor *bme_humidity = bme.getHumiditySensor();

void setup() {
  Serial.begin(9600);
  Serial.println(F("BME280 Sensor event test"));

  if (!bme.begin()) {
    Serial.println(F("No BME280 sensor found"));
    while (1) delay(10);
  }
  
  bme_temp->printSensorDetails();
  bme_pressure->printSensorDetails();
  bme_humidity->printSensorDetails();
}

void loop() {
  sensors_event_t temp_event, pressure_event, humidity_event;
  bme_temp->getEvent(&temp_event);
  bme_pressure->getEvent(&pressure_event);
  bme_humidity->getEvent(&humidity_event);
  
  Serial.print(F("Temperature = "));
  Serial.print(temp_event.temperature);
  Serial.println(" *C");

  Serial.print(F("Humidity = "));
  Serial.print(humidity_event.relative_humidity);
  Serial.println(" %");

  Serial.print(F("Pressure = "));
  Serial.print(pressure_event.pressure);
  Serial.println(" hPa");

  Serial.println();
  delay(1000);
}

Download the code

All the code from this post is available for download on Github. github-full