#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
DHT dht (4, DHT22);
int pinled_red = 12;
int pinled_blue = 25;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(pinled_red, OUTPUT);
pinMode(pinled_blue, OUTPUT);
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3c)){
Serial.println(F("Failed to start SSD1306 OLED"));
while(1);
}
delay(1000);
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,2);
oled.println("Hello World");
oled.display();
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
float temp = dht.readTemperature();
float hum = dht.readHumidity();
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,2);
oled.print("Suhu: ");
oled.println(temp);
oled.print("Kelembapan: ");
oled.println(hum);
oled.display();
if(temp >= 30){
digitalWrite(pinled_red, HIGH);
digitalWrite(pinled_blue, LOW);
delay(500);
digitalWrite(pinled_red, LOW);
digitalWrite(pinled_blue, LOW);
}else{
digitalWrite(pinled_red, LOW);
digitalWrite(pinled_blue, HIGH);
}
}