#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
//#define DHTTYPE DHT11
//#define DHTTYPE DHT21
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,16,2); // 접근주소: 0x3F or 0x27
void setup() {
Serial.begin(9600);
dht.begin();
lcd.init(); // LCD 초기화
lcd.backlight(); // LCD 백라이트 켜기
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
lcd.setCursor(0,0); lcd.print("TEMP: "); lcd.print(t);
lcd.setCursor(0,1); lcd.print("HUMID: "); lcd.print(h);
Serial.print("Humidity: ");
Serial.print(h,1);
Serial.print("% Temperature: ");
Serial.print(t,1);
Serial.print("C & ");
Serial.print(f,1);
Serial.println("F");
int ldr = A2;
int led = 8;
int nilai;
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led, OUTPUT);
// put your main code here, to run repeatedly:
nilai = analogRead(ldr);
Serial.print("Nilai LDR : ");
Serial.println(nilai);
if(nilai > 800){
digitalWrite(led, HIGH);
Serial.println("Keadaan gelap, relay menyala");
}else{
digitalWrite(led, LOW);
Serial.println("Keadaan terang, relay mati");
}
delay(1000);
}