int LEDMERAH = 5;
int LEDKUNING = 6;
int LEDBIRU = 7;
int BUZZER = 8;
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/Picopixel.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
void setup() {
// put your setup code here, to run once:
pinMode(LEDMERAH, OUTPUT);
pinMode(LEDBIRU, OUTPUT);
pinMode(LEDKUNING, OUTPUT);
pinMode(BUZZER, OUTPUT);
dht.begin();
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setFont();
display.setTextColor(1);
}
void loop() {
// put your main code here, to run repeatedly:
float TEMP = dht.readTemperature();
//Serial.print("Temperature");
//Serial.println(TEMP);
if (TEMP < 29.0 ){
digitalWrite(LEDBIRU, HIGH);
digitalWrite(LEDMERAH, LOW);
digitalWrite(LEDKUNING, LOW);
display.clearDisplay();
display.setCursor(32, 20);
display.print("SUHU RENDAH");
display.display();
noTone(BUZZER);
}
if (TEMP >= 29 && TEMP <=35){
digitalWrite(LEDBIRU, LOW);
digitalWrite(LEDMERAH, LOW);
digitalWrite(LEDKUNING, HIGH);
display.clearDisplay();
display.setCursor(32, 20);
display.print("SUHU CUKUP");
display.display();
noTone(BUZZER);
}
if (TEMP > 35){
tone(BUZZER, 500);
digitalWrite(LEDBIRU, LOW);
digitalWrite(LEDMERAH, HIGH);
digitalWrite(LEDKUNING, LOW);
display.clearDisplay();
display.setCursor(32, 20);
display.print("SUHU PANAS");
display.display();
}
}