This is a troubleshooting guide for the BME280 temperature, humidity, and pressure sensor when using ESP32, ESP8266, Arduino, or similar boards.
If you get an error message in your Serial Monitor when trying to initialize the BME280 sensor, go through the following steps to understand what might be causing the issue and how to fix it.
If you get the following error Could not find a valid BME280 sensor, check wiring! when trying to initialize the BME280 sensor, it might be one of the following issues:
1. Check Wiring
BME280 sensor modules are available in different formats—with 4 pins and with 6 pins.
4-pin model BME280
The models with 4 pins only allow I2C communication protocol like the module shown in the picture below.
You must wire the SDA and SCL pins to your microcontrollers’ I2C pins. The following table shows the default I2C pins for the ESP32, ESP8266, and Arduino Uno boards:
BME280 | ESP32 | ESP8266 | Arduino Uno |
SCL | GPIO 22 | GPIO 5 (D1)* | A5 |
SDA | GPIO 21 | GPIO 4 (D2)* | A4 |
* in most ESP8266 development boards, GPIO 5 is labeled on the board as D1 and GPIO 4 as D2. For more information check the ESP8266 pinout guide.
Besides the I2C pins, you should connect the VIN pin (also labeled VCC on some modules) to 3.3V and GND to the microcontroller’s GND pin.
6-pin model BME280
There are models with 6 pins that support both I2C and SPI communication protocol.
If you want to use I2C communication protocol with these models, you need to wire the sensor’s I2C pins to your microcontroller’s I2C pins. In this case, the SDI label corresponds to the SDA pin and the SCK to the SCL pin.
BME280 | ESP32 | ESP8266 | Arduino Uno |
SCL (SCK) | GPIO 22 | GPIO 5 (D1)* | A5 |
SDA (SDI) | GPIO 21 | GPIO 4 (D2)* | A4 |
Besides the I2C pins, you should connect the VIN pin (also labeled VCC on some modules) to 3.3V and GND to the microcontroller’s GND pin.
If you want to use SPI communication protocol, you need to connect the sensor’s SPI pins to your microcontroller’s SPI pins. The following table shows the connection to the default SPI pins.
BME280 | ESP32 | ESP8266 | Arduino Uno |
SCK (SPI Clock) | GPIO 18 | GPIO 14 (D5) | Pin 13 |
SDO (MISO) | GPIO 19 | GPIO 12 (D6) | Pin 12 |
SDI (MOSI) | GPIO 23 | GPIO 13 (D7) | Pin 11 |
CS (Chip Select) | GPIO 5 | GPIO 15 (D8) | Pin 10 |
Besides the I2C pins, you should connect the VIN pin (also labeled VCC on some modules) to 3.3V and GND to the microcontroller’s GND pin.
2. Check I2C Address
If you’re using I2C communication protocol, and your board can’t find the BME280 sensor, it might be the case that you’re not using the correct I2C address. Usually, the BME280 I2C sensor is 0x76, but it might be different. So, we recommend running an I2C scanner sketch to find the sensor’s I2C address.
/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print("Unknow error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
}
else {
Serial.println("done\n");
}
delay(5000);
}
After getting the I2C sensor address, make sure you use the right address in your code. For example, in most of our projects, we use the Adafruit BME280 library. In that case, we must pass the address to the begin() method as follows:
bme.begin(YOUR_SENSOR_I2C_ADDRESS)
If the I2C scanner sketch returns 0x76 or any other address and you still can’t get it working, go to issue 4.
3. Broken/fried Sensor
If your microcontroller can’t find the sensor’s I2C address and you’re sure the wiring is correct, you probably have a hardware problem:
- your sensor might be broken;
- faulty wires;
- insufficient power supply;
We recommend checking all the wiring again.
4. Fake BME280 Sensor (BMP280)
Some vendors sell BMP280 sensor modules as BME280. It is very difficult to tell the difference between them when buying because they are very similar. BME280 sensors are usually more expensive than BMP280 sensors. The downside of having a BMP280 is that it doesn’t measure humidity, it only measures temperature and pressure.
How to tell if you got a BMP280 sensor? In the following picture, you can see that the BME280 sensor chip is square-shaped, while the BMP280 is more like a rectangle shape.
To be sure that you have a BMP280 sensor, you can install a library compatible with the BMP280 sensor and run an example sketch.
I usually recommend installing the Adafruit BMP280 library and running the bmp280test sketch that you can find here.
- Library: Adafruit BMP280 Library
- Sketch: bmp280test.ino
You can use the sketch straight away if you’re using I2C communication protocol, or if you want to use SPI, you need to modify the sketch to use the right SPI pins.
If you got it working with the BMP280 test sketch, it means you have a BMP280 and not a BME280.
Wrapping Up
In this article, we’ve described the most common issues that might cause the “Could not find a valid BME280 sensor, check wiring!” error when using a BME280 sensor with the ESP32, ESP8266, Arduino, or other development boards.
We hope you were able to solve your issue with our tips.
We have many BME280 sensor guides that you might find useful:
- ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)
- ESP8266 with BME280 using Arduino IDE (Pressure, Temperature, Humidity)
- Guide for BME280 Sensor with Arduino (Pressure, Temperature, Humidity)
- MicroPython: BME280 with ESP32 and ESP8266 (Pressure, Temperature, Humidity)
Thanks for reading.
Very timely Sara, I have several of these things lying around that I couldn’t get to work. Perhaps now I can make use of them 🙂 thanks.
I remember when I first tried this sensor and the BME280 it was all a bit confusing what with the clones having what looked like a dual description but once you figure that out and can identify which one you have there is still going to be a problem which I’d say Adafruit have created purposely and you can’t really blame them for as if you’re using their library you should use their sensor.
Anyway, most of us don’t and all you need to remember is the Adafruit versions will use 0x77 as the I2C default address but the clones use 0x76. So if you have a clone just open the libraries header file and a few line down is the “#define BMP280_ADDRESS (0x77) ” & “#define BMP280_ADDRESS_ALT \ (0x76)”. Just swap these address’s round and problem is solved. Remember to also do this after the libraries have been updated also (chased my tail on that a few times).
Cheers
Alternatively, you can connect SD0 to Gnd to flip the device address to 0x77.
I can get my devices to work perfectly on ESP8266 but not on ESP32.
Wiring is OK, double checked with a CRO!
I will investigate other libraries, mentioned further down this page.
As I vaguely recall, there is another issue with the internal control on some of the clone BME280’s and the Adafruit library doesn’t access these controls properly regardless of the I2C address. I have experienced this issue in the past. There is an alternative library called cactus.io and that has worked perfectly for me with all BME280 devices I have tested.
The alternative library is a very good option to add to the BME device check tool kit. Personally once I have checked the wiring I run the I2C scanner. In fact I put the code into a routine that I can load in all my projects that use multiple I2C devices. I then call that routine to test I2C communication and then disable it once the devices are all recognised.
Hi Bob.
Thanks for sharing this info.
Regards,
Sara
Hi,
In i2c specs, a 4k7 ohms on the data lines are mandatory.
Does it mean that these resistors are embedded in the PCB sensor?
Cheers
Yes.
The Adafruit BME280 library is rather inefficient. When it calls the humidity or pressure, it first makes a call to the temperature. This call in fact returns all 3 values, but only one is selected.
So if you need al 3 values, you need to make 3 calls, where only one call would be sufficient.
Believe temperature has to be known to calculate barometric pressure; is why it is called first.
Recommend alternative BME280 library; BME280 by Tyler Glenn, it does dew point and heat index calculations and more, plus it allows calibration.
“Ensure your pressure sensor or barometer readings are correct by using a METAR station, these are highly accurate weather stations provided for aircraft altimeter adjustments. There are 1000’s around the world for nearly all known locations.” –G6EJD – David
G6EJD – David BME29- calibration video: https://www.youtube.com/embed/Wq-Kb7D8eQ4
Perfect. Turns out I had the BMP280. Great tutorials – I’ve learned heaps and will sign up for one of the courses shortly.
Thank you.
Regards,
Sara
I modify I2C-scanner a bit. My version give all sensor addresses and type of sensor.
Now you can easily identify all Bosch sensors (type and address).
https://github.com/hraHoo/I2C-scanner
Thanks for sharing.
Regards,
Sara
Nice job! It showed me I received a BMP280 and not the expected BME280
Be warned. I received a batch of these sensors and have been banging my head trying to figure out why this simple little board does NOT work.
I took a closer look and found that the sensor chip is soldered backwards. The manufacturer of this board is sloppy. Sometimes you get what you pay for.
Hi.
Thanks for sharing your experience.
Regards,
Sara
I think I’m facing the same problem, judging by the date it might even be the same batch haha. I ordered two BMP280 sensors from a chinese supplier on aliexpress and i’ve spent 2 days trying to make them work but they don’t even show up in the i2c scanner. Looking at my sensors and the ones online, I think they might indeed have been soldered backwards…
I’m almost sure it is also backwards in the shop page, you can clearly see that the pin soldered to the i2c address selector is 1-GND (the one next to the vent hole) instead of 5-SDO (the opposite pin), which according to the datasheet must be pulled down to ground or to vcc to select the last I2C address bit.
Hi,
I can’t get the version to run.
When compiling, various error messages come up. What am I doing wrong?
Can you help a (beginner) a little further?
Thanks!
Excerpt from error messages:
C:\Users\Florian\Documents\Arduino\I2C_scanner\I2C_Scanner.ino:129:31: note: in expansion of macro ‘HDC10xx_Device_ID’
uint16_t chip_id = Read16(HDC10xx_Device_ID, address); // get chip ID
^~~~~~~~~~~~~~~~~
I2C_Scanner:129:14: error: unused variable ‘chip_id’ [-Werror=unused-variable]
uint16_t chip_id = Read16(HDC10xx_Device_ID, address); // get chip ID
^~~~~~~
cc1plus.exe: some warnings being treated as errors
Bibliothek Wire in Version 2.0.0 im Ordner: C:\Users\Florian\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\libraries\Wire wird verwendet
exit status 1
unused variable ‘chip_id’ [-Werror=unused-variable]
I got caught out with the fake BME280. It was a BMP280 clearly marked as a BME280.
If the AdafruitBME280 library is used, the sketch will NOT find a BMP280, whereas some of the other BMP280 libraries will.
In the ESP32 gauges sketch changing to the BMP280 library , the fake BME280(BMP280) was found OK.
I have found that some bmp 280 boards do not have the required 4k7 pullup resistors on board. Particularly ones from AZ-Delivery! I have a couple of these and wondered why they worked with a raspberry pi pico dev board and not my ESP32 boards. It turned out the pico board had the built in pull ups.
Hi.
I didn’t know about that.
Thanks for sharing.
Regards,
Sara
I found I had a problem getting reliable humidity readings (Kept returning 82%). It turned out the fix for me was to lower the I2C bus speed . Originally I had it set to 400K, I dropped it to 20K and things worked normally. I was connecting to a Pico W and using micropython.
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=20000)
Cheers David
Hello, thank you so much. Finally, I discovered why the BME 280 wasn’t working. It was a fake !
Regards.
I have used the solution provided by Ralph McCleery above, meaning editing the “Adafruit_BMP280.h” file in order to twist the (0x77) and (0x76) addresses, and it worls perfectly !
If someone could test other(s) librairy(ies) that would work without any modification, it would be simpler in case we use different sensors (originals and clones) with the same program…
Amongst the possible alternatives to the “Adafruit_BMP280” library, I have been told that the “cactus.io” and the “Sparkfun” (it works with a BME280, but does it work with a BMP280 ??) have a better reputation than the Adafruit_BMP280.
Thank for sharing,
Michel