int ldr = 13;
int led = 15;
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 < 500){
digitalWrite(led, HIGH);
Serial.println("Keadaan gelap, lampu menyala");
}else{
digitalWrite(led, LOW);
Serial.println("Keadaan terang, lampu mati");
}
delay(1000);
}