I've been working on a project in which I need to know my altitude. For this purpose I've been using the BMP280 sensor. But I have an issue.

I've been trying to test if the sensor works with the program "bmp280_sensortest.ino", already included in the library. When I open the serial monitor the message "BMP280 Sensor event test" is displayed, indicating that there is a valid sensor on board. Below that the temperature, pressure and altitude data should be displayed, but nothing happens.

I've added a simple Serial.print("hello") at the start of void loop(), but not even that is displayed. The program doesn't seem to enter void loop() and I don't know why.

Here is the code:

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

Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();

void setup() {
  Serial.println(F("BMP280 Sensor event test"));

  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1) delay(10);

  /* Default settings from datasheet. */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */


void loop() {
  sensors_event_t temp_event, pressure_event;
  Serial.print(F("Temperature = "));
  Serial.println(" *C");

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


Any reply is greatly appreciated. edit:

if I remove !bmp.begin()

from the if statement and replace it with a 1 it enters the void loop but it displays 0°C and 0pa

  • If you are using Serial.print("hello"); to test the entering of void loop(), you should follow it with Serial.flush(); so that you know your message has been sent before your code has an opportunity to lock up, because if that happens the absence of the "Hello" message might lead you to believe that you didn't make it to that line when you in fact did.
    – timemage
    Feb 19, 2021 at 17:12
  • put print statements throughout setup()
    – jsotola
    Feb 19, 2021 at 17:43
  • 1
    But you don't get the "check wiring" message? ;)
    – Sim Son
    Feb 19, 2021 at 18:04
  • Add prints after every call in setup to pin down which of those calls does not return...
    – Sim Son
    Feb 19, 2021 at 18:06
  • 1
    @timemage the I2C scanner sketch is stuck at 'scanning...'
    – Leko Mleko
    Feb 19, 2021 at 18:31

1 Answer 1


It could be a faulty library/sensor, most likely the sensor, sometimes sensors can begin but then another connection could be faulty or the chip itself is faulty and so the Arduino might just be waiting forever for a response that will never come.

To see where it gets stuck, you can add Serial.println(F("1")); after bmp.setsampling then Serial.println(F("2")); after bmp_temp->printSensorDetails to see where exactly it's getting stuck

One thing I also like to do is to buy two/three of a sensor, so that I can replace a sensor with another one. That way if a piece of code doesn't work for all three sensors then I can pretty sure it's a problem with the code and not the device. Not sure if you have a spare sensor to try that but I would recommend it in future

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.