Advertisement
microrobotics

BME280 Arduino Code Example

Oct 16th, 2023
2,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_Sensor.h>
  3. #include <Adafruit_BME280.h>
  4.  
  5. #define SEALEVELPRESSURE_HPA (1013.25) // Change this to your local sea level pressure (hPa)
  6.  
  7. Adafruit_BME280 bme;
  8.  
  9. void setup() {
  10.   Serial.begin(9600);
  11.   if (!bme.begin(0x76)) {
  12.     Serial.println("Could not find a valid BME280 sensor, check wiring!");
  13.     while (1);
  14.   }
  15. }
  16.  
  17. void loop() {
  18.   Serial.print("Temperature = ");
  19.   Serial.print(bme.readTemperature());
  20.   Serial.println(" *C");
  21.  
  22.   Serial.print("Humidity = ");
  23.   Serial.print(bme.readHumidity());
  24.   Serial.println("%");
  25.  
  26.   Serial.print("Pressure = ");
  27.   Serial.print(bme.readPressure() / 100.0F); // hPa to Pa conversion
  28.   Serial.println(" hPa");
  29.  
  30.   Serial.print("Approx. Altitude = ");
  31.   Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  32.   Serial.println(" m");
  33.  
  34.   Serial.println();
  35.  
  36.   delay(2000); // Delay for 2 seconds (2000 ms) between each reading
  37. }
  38.  
Tags: BME280
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement