//* Project Atap Otomatis dengan Dua Buah Servo dan Sensor Cahaya
//* Dibuat Oleh : kyy
// menambah library servo
#include <Servo.h>
// inialisasi variabel kedua servo
Servo myservo1, myservo2;
// inialisasi pin sensor cahaya
const int pinLdr = 4;
// inialisasi variabel pembacaan sensor
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(60);
myservo2.write(60);
}
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);
}
}