BMP280 Sensor wrong readings

Hello everyone.

I recently bought a weird BMP280 sensor, but I'm having some problems with it. It has 6 pins, while most images I've seen on the internet have 4 only, so I'm now using these 4 pins (VCC, GND, SDA, SCL). There is two more pins labeled CSB and SDO, don't know if I should be using these.

I've also seen that the default I2C address of the BMP sensor is 0x77, and BME is 0x76. My sensor has an address of 0x76, so I tried to use the Adafruit BME280 library but got nan readings, while BMP280 library works just fine.

But after around 5-10 minutes of running (sometimes up to 20), the sensor starts showing very weird values, like 170°C and negative pressures. When I unplug my board from my computer and replug it, the code restarts and the values are fine, but it starts showing these wrong values again after some time. I'm using a NodeMCU.

I've been trying to solve this problem for some days, searching over the internet, I tried many solutions but none of them seem to work. This is my current code in the loop() function:

  Serial.println();
  Serial.println("Reading from BMP280 Sensor");
  Serial.println();
  
  float bmp_temp = bmp.readTemperature();
  float pressure = bmp.readPressure() / 100.0F;
  float altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);

  if (bmp_temp > 100 || pressure < 0) {
    Serial.println("BMP280 ERROR");
    Serial.print("Temperature = ");
    Serial.println(bmp_temp);
    Serial.println();
    Serial.print("Pressure = ");
    Serial.println(pressure);
    Serial.println();
    Serial.print("Altitude = ");
    Serial.println(altitude);
    Serial.println();
    Serial.println("Resetting BMP280 sensor...");
    Serial.println();
    bmp.reset();
    delay(1500);
    Serial.println("Restarting loop...");
    delay(1500);
    return;
  }

I made this if condition to detect wrong readings and try to reset the sensor, but the bmp.reset() doesn't seem to do anything.

I also saw these functions:

bmp280.initialize();
bmp280.setEnabled(0);

But when compiling the code, I got an error that they don't exist.

This is the current output of the code as I'm posting:

22:01:04.617 -> Reading from BMP280 Sensor
22:01:04.663 -> 
22:01:04.663 -> Temperature = 26.49°C
22:01:04.663 -> Pressure = 994.00hPa
22:01:04.710 -> Altitude = 186.34m
22:01:06.621 -> 
22:01:06.759 -> 
22:01:06.759 -> Reading from BMP280 Sensor
22:01:06.806 -> 
22:01:06.806 -> BMP280 ERROR
22:01:06.946 -> 
22:01:06.946 -> Temperature = 180.32
22:01:06.946 -> 
22:01:06.946 -> Pressure = -135.30
22:01:06.992 -> 
22:01:06.992 -> Altitude = nan
22:01:06.992 -> 
22:01:06.992 -> Resetting BMP280 sensor...
22:01:07.039 -> 
22:01:08.392 -> Restarting loop...
22:01:09.882 -> 
22:01:10.024 -> Reading from BMP280 Sensor
22:01:10.072 -> 
22:01:10.072 -> BMP280 ERROR
22:01:10.213 -> 
22:01:10.213 -> Temperature = 180.32
22:01:10.213 -> 
22:01:10.213 -> Pressure = -135.30
22:01:10.259 -> 
22:01:10.259 -> Altitude = nan
22:01:10.259 -> 
22:01:10.259 -> Resetting BMP280 sensor...
22:01:10.306 -> 
22:01:11.662 -> Restarting loop...
22:01:13.154 -> 

If this helps, I'm using pins D1 and D2 on my NodeMCU for I2C, and I also have an I2C LCD connected to these same pins on the breadboard.

Any help is appreciated. Thanks in advance!

The other pins are for a SPI connection, a faster way to access data.

Post an image of your project, all powered up.

Code sippets are poo! Please post all your code.

Does the display start showing errors?

Different libraries can have different methods.

The LCD always works well, never did something weird.

Here is my code, if you feel like you need all of it, and an image of the circuit for your reference:

#include <DHT.h>
#include <Wire.h> 
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <LiquidCrystal_I2C.h>

#define SEALEVELPRESSURE_HPA (1016.20)
#define DHTPIN D7
#define DHTTYPE DHT11 

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Adafruit_BMP280 bmp;

void setup() {
  pinMode(D0, OUTPUT);
  bmp.begin(0x76);
  dht.begin();
  lcd.begin();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.backlight();
  Serial.begin(9600);

  digitalWrite(D0, LOW);
}

void loop() {
  
  lcd.setCursor(0,0);
  
  // READING FROM DHT11 SENSOR

  Serial.println();
  Serial.println("Reading from DHT11 Sensor");
  Serial.println();
  
  float humidity = dht.readHumidity();
  float dht_temp_c = dht.readTemperature();
  
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float dht_temp_f = dht.readTemperature(true);
  
  if (isnan(humidity) || isnan(dht_temp_c) || isnan(dht_temp_f)) {
    Serial.println("Failed to read from DHT sensor!");
    delay(1000);
    return;
  }
  
  float bmp_temp_ = bmp.readTemperature();
  
  float heat_index_f = dht.computeHeatIndex(dht_temp_f, humidity);
    
  // Compute heat index in Celsius (isFahreheit = false)
  float heat_index_c = dht.computeHeatIndex(bmp_temp_, humidity, false);
    
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print("%");
  Serial.println();
    
  Serial.print("Temperature: ");
  Serial.print(dht_temp_c);
  Serial.print("°C, ");
  Serial.print(dht_temp_f);
  Serial.print("°F");
  Serial.println();
  
  Serial.print("Heat index: ");
  Serial.print(heat_index_c);
  Serial.print("°C, ");
  Serial.print(heat_index_f);
  Serial.println("°F");
  Serial.println();

  // READING FROM BMP280 SENSOR

  Serial.println();
  Serial.println("Reading from BMP280 Sensor");
  Serial.println();
  
  float bmp_temp = bmp.readTemperature();
  float pressure = bmp.readPressure() / 100.0F;
  float altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);

  if (bmp_temp > 100 || pressure < 0) {
    Serial.println("BMP280 ERROR");
    Serial.print("Temperature = ");
    Serial.println(bmp_temp);
    Serial.println();
    Serial.print("Pressure = ");
    Serial.println(pressure);
    Serial.println();
    Serial.print("Altitude = ");
    Serial.println(altitude);
    Serial.println();
    Serial.println("Resetting BMP280 sensor...");
    Serial.println();
    bmp.reset();
    delay(1500);
    Serial.println("Restarting loop...");
    delay(1500);
    return;
  }

  // Printing Data
  
  Serial.print("Temperature = ");
  Serial.print(bmp_temp);
  Serial.print("°C");
  Serial.println();
  
  Serial.print("Pressure = ");
  Serial.print(pressure);
  Serial.print("hPa");
  Serial.println();
  
  Serial.print("Altitude = ");
  Serial.print(altitude);
  Serial.print("m");
  Serial.println();

  lcd.setCursor(0,0);
  lcd.print("T=");
  lcd.setCursor(2,0);
  lcd.print(bmp_temp);

  lcd.setCursor(9,0);
  lcd.print("H=");
  lcd.setCursor(11,0);
  lcd.print(humidity);
  
  lcd.setCursor(2,1);
  lcd.print("P=");
  lcd.setCursor(5,1);
  lcd.print(pressure);
  lcd.setCursor(11,1);
  lcd.print("hPa");

  delay(2000);
}

Hope the image is clear enough.

1 Like

After looking over the posted image, things look all right. Is the BMP280 being used of the 5V or 3.3V variety?

I'm currently using it with 5V, since most of the online tutorials that I read mention that. How do I know if it should be used with 3.3V or 5V?

I'm in the ESP8266 and ESP32 are not 5V tolerant camp.

When I look at Amazon the BMP280s they are listed at either being the 5V model or the 3.3V model.

I know you want to work with the stuff you got. I'd use a BME280 instead of the BMP280 and the DHT, I'd use the BME280's SPI buss instead of I2C.

1 Like

The problem is that I originally ordered a BME280 but received this. I know it is a better sensor and I probably wouldn't need the DHT anymore, but when I talked to the seller they said they don't have a BME available and might take a few weeks to supply it. I couldn't wait because this is a university project that I have to submit next week.

I'll try the sensor with 3.3V, and also lookup the SPI. Thanks for the suggestions!

1 Like

Hello again.

Just an update on this topic.

Today I've connected my BMP280 sensor to the 3V3 pin of the NodeMCU, it's been working for almost 2 hours non-stop now! So I think that was probably the problem. And I'm still using I2C communication.

Thank you for bringing my attention to this!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.