int inputPin = 2;               
int pirState = LOW;             
int val = 0;                    
const int relayPin = 12;

void setup() {
  pinMode(inputPin, INPUT);     
  pinMode( relayPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  
  if (val == HIGH) {            
    digitalWrite(relayPin, HIGH);  
    if (pirState == LOW) {
      Serial.println("Gempa Terdeteksi!");
      pirState = HIGH;
    }
  } else {
    digitalWrite(relayPin, LOW);
    if (pirState == HIGH) {
      Serial.println("Gempa Berakhir!");
      pirState = LOW;
    }
  }
}