Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created September 21, 2023 08:04
Show Gist options
  • Save kakopappa/2679aef963d8843ce1a7171dadb517d7 to your computer and use it in GitHub Desktop.
Save kakopappa/2679aef963d8843ce1a7171dadb517d7 to your computer and use it in GitHub Desktop.
BME280
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // Default I2C
void setup() {
Serial.begin(9600);
bool status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find BME280 sensor!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
// Convert temperature to Fahrenheit
/*Serial.print("Temperature = ");
Serial.print(1.8 * bme.readTemperature() + 32);
Serial.println(" *F");*/
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Altitude (Approx) = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
delay(1000);
}
// Ref: https://github.com/adafruit/Adafruit_BME280_Library/blob/master/examples/bme280test/bme280test.ino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment