int buzzer =2;
int pir = 14;
int pirState = LOW;             // we start, assuming no motion detected
int val = 0; 
int ledMerah = 19;
int ledHijau = 18;

void setup() {
  pinMode(buzzer, OUTPUT);
  pinMode(pir, INPUT);
  pinMode(ledMerah, OUTPUT);
  pinMode(ledHijau, OUTPUT);
  Serial.begin(9600);
}

void loop() {
   val = digitalRead(pir);  // read input value
  if (val == HIGH) {     
    digitalWrite(ledMerah, HIGH);
    digitalWrite(ledHijau, LOW);
    digitalWrite(buzzer, HIGH);
    tone(buzzer, 1000, 100);
    delay(500);
    if (pirState == LOW) {
      // we have just turned on
       Serial.println("Gerakan Asing Terdeteksi");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    if (pirState == HIGH) {
      digitalWrite(ledHijau, HIGH);
      digitalWrite(ledMerah, LOW);
      digitalWrite(buzzer, LOW);
      // we have just turned of
      Serial.println("Aman");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}