int ldr = A5;
int led = 9;
int nilai;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
// 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);
}