#include <Servo.h>
Servo myservo1, myservo2;
const int pinLdr = 4;
int bacaSensorLDR;
void setup()
{
// inialisasi pin servo 1 dan 2
myservo1.attach(9);
myservo2.attach(10);
// inialisasi status I/O pin
pinMode(pinLdr, INPUT);
// pengaturan derajat awal servo (menutup)
myservo1.write(90);
myservo2.write(90);
}
void loop()
{
// membaca output sensor
bacaSensorLDR = digitalRead(pinLdr);
if (bacaSensorLDR == LOW)
{
myservo1.write(0);
myservo2.write(0);
delay(1000);
}
else if (bacaSensorLDR == HIGH)
{
myservo1.write(90);
myservo2.write(90);
delay(1000);
}
}