#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#define buzzer 10
#define DHTPIN 2
#define DHTTYPE DHT22
float h;
float t;
float f;
DHT dht(DHTPIN, DHTTYPE);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
dht.begin();
}
void loop () {
delay(2000);
h = dht.readHumidity();
t = dht.readTemperature();
f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
return;
}
if ((h > 75) || (t > 35)) {
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
display.clearDisplay();
display.setCursor(0, 0);
display.println(" ");
display.print("Humidity: ");
display.print(h);
display.println("%");
display.println(" ");
display.print("Temp: ");
display.print(t);
display.print("C(");
display.print(f);
display.println("F)");
display.display();
}