Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*The Adafruit BME280 is a digital temperature and humidity sensor that communicates over I2C or SPI. Here's an example code in Arduino that reads the temperature, pressure, and humidity from the sensor using the I2C interface:
- Note: This code assumes that the Adafruit BME280 sensor is connected to the I2C bus of the Arduino board with the I2C address 0x76. If you're using a different I2C address or interface, you'll need to modify the bme initialization accordingly.
- */
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- Adafruit_BME280 bme; // create an instance of the sensor
- void setup() {
- Serial.begin(9600);
- if (!bme.begin(0x76)) { // initialize the sensor with the I2C address 0x76
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- while (1);
- }
- }
- void loop() {
- // read the temperature, pressure, and humidity from the sensor
- float temperature = bme.readTemperature();
- float pressure = bme.readPressure() / 100.0;
- float humidity = bme.readHumidity();
- // print the temperature, pressure, and humidity
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- Serial.print("Pressure: ");
- Serial.print(pressure);
- Serial.println(" hPa");
- Serial.print("Humidity: ");
- Serial.print(humidity);
- Serial.println(" %");
- // delay before reading from the sensor again
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement