#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
const int ledPin = 2;
#define DHTPIN 5
#define DHTTYPE DHT22
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT suhu(DHTPIN, DHTTYPE);
const int freq = 1000;//
const int ledChannel = 0;//
const int resolution = 8;//
void keliphidup(){//
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(10);
}
}
void kelipmati(){//
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(10);
}
}//
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.init();
lcd.backlight();
pinMode(ledPin, OUTPUT);
delay(1000);
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
}
void loop() {
float t = suhu.readTemperature();
float k = suhu.readHumidity();
delay(10); // this speeds up the simulation
if(t>30){
/* digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
lcd.print("Temp: ");
lcd.print(t);
delay(1000);
lcd.clear();
lcd.print("Lembab: ");
lcd.print(k);
delay(1000);
lcd.clear();
lcd.print("Suhu Tinggi! kelembaban tinggi");
delay(5000);
lcd.clear();
*/
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print("Temp: ");
lcd.print(t);
delay(1000);
lcd.clear();
lcd.print("Lembab: ");
lcd.print(k);
delay(1000);
lcd.clear();
lcd.print("Suhu Tinggi!");
delay(1000);
lcd.clear();
lcd.print("Kelembaban Tinggi");
delay(5000);
lcd.clear();
kelipmati();
}
else if(t<=10&&k<=10){
/* digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
lcd.print("Temp: ");
lcd.print(t);
delay(1000);
lcd.clear();
lcd.print("Lembab: ");
lcd.print(k);
delay(1000);
lcd.clear();
lcd.print("Suhu Rendah! kelembaban rendah");
delay(5000);
lcd.clear();
*/
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print("Temp: ");
lcd.print(t);
delay(1000);
lcd.clear();
lcd.print("Lembab: ");
lcd.print(k);
delay(1000);
lcd.clear();
lcd.print("Suhu Rendah!");
delay(1000);
lcd.clear();
lcd.print("Kelembaban Rendah");
// kelipmati();
}
}