byte ldr = A5;
byte led = 9;
int nilai;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
nilai = analogRead(ldr);
Serial.print("Nilai LDR : ");
Serial.println(nilai);
if(nilai < 500){
digitalWrite(led, HIGH);
Serial.println("Keadaan gelap, lampu menyala");
}else{
digitalWrite(led, LOW);
Serial.println("Keadaan terang, lampu mati");
}
delay(1000);
}