#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
DHT dht(27, DHT22);
int buz = 19;
int chan = 0;
int white = 34;
int blue = 35;
int red = 32;
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
Serial.println("Ridho Fernando");
dht.begin();
ledcAttachPin(buz, chan);
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3c)){
Serial.println(F("Failed to start SSD1306 OLED"));
while (1);
}
pinMode(white, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(red, OUTPUT);
}
void loop() {
float temp = dht.readTemperature();
Serial.print("Suhu Ruangan : ");
Serial.println(temp);
delay(1000);
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0, 2);
oled.print("Suhu ruangan: ");
oled.println(temp);
oled.display();
if (temp < 15){
digitalWrite(red, HIGH);
}
}
Loading
ssd1306
ssd1306