Temperature, Humidity Sensor Tutorial for BME280 Sensor

In this section we’ll walk through creating a Temperature Sensor using ESP32, ESP8266 and then view the temperature via Alexa, Google Home or SmartThings.

Prerequisites :

  1. ESP32, ESP8266 x 1.
  2. BME280 x 1.
  3. Jumper Wires.

Quick introduction to BME280 Temperature Sensor

The BME280 uses a temperature sensor based on the principle of thermal resistance. As the temperature changes, the resistance of the sensor changes. The BME280 measures this change in resistance and uses it to calculate the temperature.

The BME280 communicates with other devices using the I2C or SPI communication protocol to exchange data with a microcontroller.

Please note that this tutorial is for BME280 not BMP280. BME280 can measure air pressure, temperature, and humidity, while else; BMP280 can only measure air pressure and temperatures.

In this tutorial, we are going to use I2C communication protocol

Wiring for BME280 with ESP8266

ESP8266 BME280 Pin
3.3V Vin
GND GND
SCL 5 (D1)
SDA 4 (D2)

Please note that you must use I2C pins in ESP8266.

Sinric Pro ESP8266 I2C Pins

Wiring for BME280 with ESP32

ESP32 BME280 Pin
3.3V Vin
GND GND
SCL 22
SDA 21

Please note that you must use I2C pins in ESP32.

Sinric Pro ESP32 I2C Pins

Sinric Pro ESP32 I2C BME280 Wiring

Let’s verify that temperature is wired correctly and working.

Step 1 : Install supporting libraries

  1. Install the BME280 library
  2. Install the Adafruit_Sensor library
  3. Install Sinric Pro Library

Sinric Pro Install the BME280 library

Step 1 : Create a new device in Sinric Pro

Sinric Pro create device alexa

Sinric Pro temperature sensor device notifications

You can set the threshold here to receive a push notification via the Sinric Pro app when the temperature goes below or above a certain temperature. Use the Retrigger Time to set the delay between notifications.

Sinric Pro copy device id

Step 2 : Connect to Sinric Pro

You can generate the code using Zero Code feature or write it by your self. If you do not have programming experice, we recommend to use Zero Code feature in the Portal to generate the code, download and flash.

2.1 Complete Code

Now you should be able to view the temperature via Sinric Pro App

Sinric Pro App Temperature Sensor

Please note that Google Home App shows the temperature sensor as a Thermostat due to Google Home limitations.

Troubleshooting

  1. This tutorial is for BME280. Make sure it’s not BMP280 module.

  2. Error: Could not find BME280 sensor!. It’s likely you have not wired correctly. You can run the I2C scanner sketch to check whether the sensor is wired correctly.

  3. BME280 by default is in auto mode for taking continuous readings. This will warm up the chip and affect the read temperature. Change to Weather Station Scenario for more accurate readings when running for a long period.

Serial.println("-- Weather Station Scenario --");
Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
Serial.println("filter off");
bme.setSampling(Adafruit_BME280::MODE_FORCED,
                Adafruit_BME280::SAMPLING_X1, // temperature
                Adafruit_BME280::SAMPLING_X1, // pressure
                Adafruit_BME280::SAMPLING_X1, // humidity
                Adafruit_BME280::FILTER_OFF   );
                    
// suggested rate is 1/60Hz (1m)
delayTime = 60000; // in milliseconds

Refer: https://github.com/adafruit/Adafruit_BME280_Library/blob/master/examples/advancedsettings/advancedsettings.ino

  1. Please refer to our common Troubleshooting page for more details.

This document is open source. See a typo? Please create an issue