#define echoPin  3 // attach pin D3 Arduino to pin Echo of HC-SR04
#define trigPin  2 // attach pin D2 Arduino to pin Trig of HC-SR04
long duration; // Variable to store time taken to the pulse to reach receiver
int distance; // Variable to store distance calculated using formula
void setup()
{
    pinMode(trigPin,OUTPUT); // Sets the trigPin as an OUTPUT
    pinMode(echoPin, INPUT);// Sets the echoPin as an INPUT
    pinMode(10,OUTPUT);
    // Serial Communication is starting with 9600 of
    // baud rate speed
    Serial.begin(9600);
    // The text to be printed in serial monitor
    Serial.println("Distance measurement using Arduino Uno.");
    delay(500);
}
void loop()
{
    int arr1[25]={0};
    int arr2[25]={0};
    for(int i=0;i<25;i++){
    digitalWrite(trigPin, LOW);
    delayMicroseconds(500); // wait for 2 ms to avoid collision in serial monitor
    digitalWrite(trigPin,HIGH); // turn on the Trigger to generate pulse
    delayMicroseconds(500); // keep the trigger "ON" for 10 ms to generate pulse for 10 ms.
   digitalWrite(trigPin,LOW); // Turn off the pulse trigger to stop pulse generation
    // If pulse reached the receiver echoPin become high Then pulseIn() returns the time taken by the pulse to reach the receiver
    duration = pulseIn(echoPin, HIGH);
    distance = duration * 0.0344 / 0.002; // Expression to calculate distance using time
    Serial.print("Distance: ");
    Serial.print(distance); // Print the output in serial monitor
    Serial.println("micro metre");
    delay(400);
    arr1[i]=distance;
    if(i==0){
      continue;
	}
    arr2[i]=arr1[i]-arr1[i-1];
    Serial.println("earthquake lvl ");
    Serial.println(abs(arr2[i]));
        if(abs(arr2[i])<=103){
            // error=false;
            Serial.println("No Earthquake");
        }
         else {
            Serial.println("Earthquake");
            digitalWrite(11,HIGH);
            delay(500);
            digitalWrite(11,LOW);
         }
    }}
