FluxBench.AIShared project · read-only

BME280 Weather Forecaster

ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic

A desk weather station: a BME280 environment sensor is read with the Adafruit BME280 library (temperature, humidity and barometric pressure over I2C), shown on a 128x64 OLED with a simple barometer forecast - RAIN below 1000 hPa, CHANGE up to 1020, FAIR above - plus a comfort word (HOT / COLD / MUGGY / COMFY). Click the BME280 on the bench and drag its T / H / P sliders while the sketch runs: the display follows, and the red LED on GPIO 4 lights as a storm warning when you drop the pressure below 1000 hPa.

sketch.ino
// BME280 Weather Forecaster - a desk weather station with a pressure-based forecast.
// Click the BME280 on the bench and drag its T / H / P sliders while the sketch
// runs - the OLED follows, the forecast flips between RAIN / CHANGE / FAIR as
// you drop or raise the pressure, and the red LED lights as a storm warning.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BME280.h>

#define STORM_PIN 4
#define RAIN_HPA 1000.0   // below this = rain likely (storm LED on)
#define FAIR_HPA 1020.0   // above this = fair weather

Adafruit_SSD1306 display(128, 64, &Wire, -1);
Adafruit_BME280 bme;

void setup() {
  Serial.begin(115200);
  pinMode(STORM_PIN, OUTPUT);
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.display();
  if (!bme.begin(0x76)) {
    Serial.println("BME280 not found - check wiring");
  }
  Serial.println("Weather station ready - drag the BME280 sliders");
}

void loop() {
  float t = bme.readTemperature();        // deg C
  float h = bme.readHumidity();           // %RH
  float p = bme.readPressure() / 100.0F;  // hPa

  bool storm = p < RAIN_HPA;
  const char* fc = "CHANGE";
  if (storm) fc = "RAIN";
  else if (p > FAIR_HPA) fc = "FAIR";
  const char* feel = "COMFY";
  if (t > 29) feel = "HOT";
  else if (t < 16) feel = "COLD";
  else if (h > 65) feel = "MUGGY";
  digitalWrite(STORM_PIN, storm ? HIGH : LOW);

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("WEATHER STATION");
  display.setTextSize(3);
  display.setCursor(0, 12);
  display.print(t, 1);
  display.setTextSize(1);
  display.print(" C");
  display.setCursor(0, 40);
  display.print("Hum ");
  display.print((int)(h + 0.5));
  display.print("%  ");
  display.print((int)(p + 0.5));
  display.print(" hPa");
  display.setCursor(0, 54);
  display.print(fc);
  display.print("  ");
  display.print(feel);
  display.display();

  Serial.print("T=");
  Serial.print(t, 1);
  Serial.print("C  H=");
  Serial.print(h, 0);
  Serial.print("%  P=");
  Serial.print(p, 1);
  Serial.print(" hPa  ");
  Serial.print(fc);
  Serial.print(" / ");
  Serial.println(feel);
  delay(500);
}

Built with FluxBench.AI — the AI workbench for embedded projects.