#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHTesp.h"
#define TINGGI_LAYAR 64 // Tinggi layar OLED yang digunakan
#define LEBAR_LAYAR 128 // Lebar layar OLED yang digunakan
const int DHT_PIN = 15;
int Buzzer = 25;
DHTesp dhtSensor;
Adafruit_SSD1306 oled(LEBAR_LAYAR, TINGGI_LAYAR, &Wire, -1);
void setup() {
Serial.begin(115200);
pinMode(Buzzer, OUTPUT);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
oled.clearDisplay();
}
void loop() {
delay(2000);
float t = dhtSensor.getTemperature();
float h = dhtSensor.getHumidity();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0, 10);
oled.println("MONITORING SUHU");
oled.setCursor(0, 20);
oled.println("& KELEMBAPAN");
oled.setCursor(0, 30);
oled.print("Suhu ");
oled.print(t);
oled.print(" C");
oled.setCursor(0, 40);
oled.print("Kelembapan ");
oled.print(h);
oled.print(" %");
delay(2000);
oled.display();
oled.clearDisplay();
if(t>40)
{
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print("Suhu ");
oled.print(t);
oled.println(" C");
oled.setCursor(0,20);
oled.print("Kelembapan ");
oled.print(h);
oled.println(" %");
oled.setCursor(0, 30);
oled.println("SUHU PANAS !!");
digitalWrite(Buzzer, HIGH);
delay(2000);
digitalWrite(Buzzer, LOW);
delay(1000);
oled.display();
oled.clearDisplay();
}
}