#include
#include
#include
#include
#include
#include
#include
#define DHTPIN 4
#define DHTTYPE DHT22
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
float previousPressure = 0.0;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
dht.begin();
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (1) {}
}
display.clearDisplay();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
float pressure = bmp.readPressure() / 100.0F; // Convert to hPa
if (isnan(temperature) || isnan(humidity) || isnan(pressure)) {
Serial.println("Failed to read from sensors!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
String weatherPrediction = predictWeather(pressure);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("Temp: "); display.print(temperature); display.println(" *C");
display.print("Hum: "); display.print(humidity); display.println(" %");
display.print("Pres: "); display.print(pressure); display.println(" hPa");
display.print("Prediction: ");
display.println(weatherPrediction);
display.display();
previousPressure = pressure;
delay(60000); // Delay for 1 minute
}
String predictWeather(float currentPressure) {
if (previousPressure == 0.0) {
previousPressure = currentPressure;
return "Gathering data...";
}
if (currentPressure > previousPressure) {
return "Improving weather";
} else if (currentPressure < previousPressure) {
return "Worsening weather";
} else {
return "Stable weather";
}
}