Arduino with bmp280 sensor not entering void loop 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 &quot;bmp280_sensortest.ino&quot;, already included in the library. When I open the serial monitor the message &quot;BMP280 Sensor event test&quot; 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(&quot;hello&quot;) 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 &lt;Wire.h&gt;
#include &lt;SPI.h&gt;
#include &lt;Adafruit_BMP280.h&gt;

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

void setup() {
  Serial.begin(9600);
  Serial.println(F(&quot;BMP280 Sensor event test&quot;));

  if (!bmp.begin()) {
    Serial.println(F(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;));
    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. */

  bmp_temp-&gt;printSensorDetails();
}

void loop() {
  sensors_event_t temp_event, pressure_event;
  bmp_temp-&gt;getEvent(&amp;temp_event);
  bmp_pressure-&gt;getEvent(&amp;pressure_event);
  
  Serial.print(&quot;hello&quot;);
  Serial.print(F(&quot;Temperature = &quot;));
  Serial.print(temp_event.temperature);
  Serial.println(&quot; *C&quot;);

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

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

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
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(&quot;1&quot;)); after bmp.setsampling then Serial.println(F(&quot;2&quot;));  after bmp_temp-&gt;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