#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd (8,6,4,3,2,1);
Servo myservo;
int led = 13;
int buzzer = 11;
int sensorPIR = 9;
void setup(){
myservo.attach (7);
pinMode(led, OUTPUT);
pinMode(sensorPIR, INPUT);
pinMode(buzzer, OUTPUT);
lcd.begin (16,2);
lcd.setCursor (0,0);
lcd.print ("pendeteksi gerak");
}
void loop(){
int pirState = digitalRead(sensorPIR);
if (pirState == HIGH) {
myservo.write(90);
tone (buzzer, 1000);
digitalWrite(led, HIGH);
lcd.setCursor (0,1);
lcd.print ("terdeteksi");
delay (2000);
}
else {
myservo.write(0);
noTone(buzzer);
digitalWrite(led, LOW);
delay(1000);
lcd.clear();
}
}