#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht (DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int red=4;
const int yellow=5;
const int green=6;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(red,OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
Serial.println("Sistem Monitoring Suhu");
lcd.begin(16, 2);
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
float t = dht.readTemperature();
//Menampilkan di LCD
lcd.setCursor(0, 0);
lcd.print("Suhu: ");
lcd.print(t);
lcd.print(" C");
if (t>35){
digitalWrite(red, HIGH);
}else{
digitalWrite (red, LOW);
}
if (t>=30 && t <=35){
digitalWrite(yellow, HIGH);
}else {
digitalWrite(yellow, LOW);
}
if (t<30){
digitalWrite(green, HIGH);
}else {
digitalWrite(green, LOW);
}
}