#define pinPir 2
#define pinRelay 3
int PirState = LOW;
int val = 0;
void setup(){
pinMode(pinPir, INPUT);
pinMode(pinRelay, OUTPUT);
Serial.begin(9600);
}
void loop(){
val = digitalRead(pinPir);
if(val == HIGH){
digitalWrite(pinRelay, HIGH);
if (PirState == LOW){
Serial.println("Ada Gerakan!");
PirState = HIGH;
}
}
else{
digitalWrite(pinRelay, LOW);
if(PirState == HIGH){
Serial.println("Tidak ada Gerakan!");
PirState = LOW;
}
}
}