Mini Weather Sensor (BME280 + Arduino)
Read temperature, humidity, and barometric pressure from a BME280 over I²C and print them to Serial.
Beginner25 min
What you need
Wiring
Hover a pin or a wire to trace the connection.
Code
bme280.ino
// Read temperature, humidity, and pressure from a BME280 over I2C.
// Install "Adafruit BME280 Library" and "Adafruit Unified Sensor".
#include <Wire.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
if (!bme.begin(0x76)) { // try 0x77 if this fails
Serial.println("BME280 not found");
while (1);
}
}
void loop() {
Serial.print("Temp: "); Serial.print(bme.readTemperature()); Serial.print(" C ");
Serial.print("Humidity: "); Serial.print(bme.readHumidity()); Serial.print(" % ");
Serial.print("Pressure: "); Serial.print(bme.readPressure() / 100.0); Serial.println(" hPa");
delay(2000);
}
Steps
- Install "Adafruit BME280 Library" and "Adafruit Unified Sensor".
- Wire the BME280: VCC to 5V (3.3V modules are fine too), GND to GND, SDA to A4, SCL to A5.
- Upload and open the Serial Monitor at 9600 baud.
- If it reports 'not found', change the address to 0x77.