← Back to Course
BME280/BMP280 - Barometric Pressure and Altitude
📊 BME280/BMP280 - Pressure, Altitude, and Weather Prediction
📊 What You'll Learn:
- 🌡️ Measure temperature, humidity, and barometric pressure
- 📈 Predict rain 12-24 hours in advance from pressure trends
- 🔌 Wire BME280/BMP280 using I2C (SDA/SCL pins)
- 💰 Choose BME280 ($10-15) or BMP280 ($5-8)
📊 Sensor Comparison
- 🌡️ BME280 ($10-15): Temperature + Humidity + Pressure → Complete weather station
- 📊 BMP280 ($5-8): Temperature + Pressure only → Budget option, no humidity
💡 Which to Choose?
BME280 is worth the extra $5 for humidity data - critical for disease prediction and crop stress monitoring. BMP280 is fine if you only need pressure for weather forecasting.
🔌 I2C Wiring (Both sensors same)
BME280/BMP280 ESP32
═══════════════ ════════
VCC ─────► 3.3V
GND ─────► GND
SDA ─────► GPIO21
SCL ─────► GPIO22
I2C Address: 0x76 (SDO to GND) or 0x77 (SDO to 3.3V)
📖 Complete Code
#include <Wire.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
float lastPressure = 0;
void setup() {
Serial.begin(115200);
Wire.begin();
if (!bme.begin(0x76)) {
Serial.println("❌ Sensor not found!");
while(1);
}
Serial.println("✅ BME280 ready");
}
void loop() {
float temp = bme.readTemperature();
float hum = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F;
float trend = pressure - lastPressure;
Serial.println("━━━━━━━━━━━━━━━━━━━━━━━━");
Serial.printf("🌡️ Temp: %.1f°C\n", temp);
Serial.printf("💧 Humidity: %.0f%%\n", hum);
Serial.printf("📊 Pressure: %.0f hPa\n", pressure);
// Weather prediction
if (trend > 2) {
Serial.println("☀️ Rising pressure - Good weather coming");
} else if (trend < -2) {
Serial.println("🌧️ Falling pressure - Rain likely soon!");
} else {
Serial.println("➡️ Stable pressure - Conditions continue");
}
lastPressure = pressure;
delay(60000);
}
💡 Weather Prediction Rules:
- 🌧️ Pressure drop > 2 hPa/hour: Rain likely in 12-24 hours
- ☀️ Pressure rise > 2 hPa/hour: Clearing weather
- ➡️ Stable pressure (±1 hPa): Current conditions continue
- 📉 Rapid drop > 4 hPa/hour: Storm approaching!
🎯 Key Takeaways:
- ✅ BME280 = Temp + Humidity + Pressure ($10-15)
- ✅ BMP280 = Temp + Pressure only ($5-8)
- 🔌 I2C pins: SDA→GPIO21, SCL→GPIO22
- 🌧️ Pressure drop = rain coming → reduce irrigation
💡 Key Takeaways:
- Apply these concepts directly to your farm or project.
- Take notes on important details for the quiz.
- Use the button below to track your progress.
×