int ldr = 0; //inisiasi variabel ldr nilai awal = 0
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A0, INPUT);
}
void loop() {
Serial.begin(9600);
ldr = analogRead(A0);
Serial.println("LDR Value Is :");
Serial.println(ldr);
delay(10);
if (ldr > 600) //jika ldr diatas 600
{
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
}
if (600 >= ldr & ldr >= 300) //jika ldr bernilai antara 600-300
{
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
}
if (ldr < 300)
{
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
}
else {}
}