How to make earthquake detector more accurate?

Hi from Turkey :slight_smile:
According to the last earthquake in turkey, most people died in their bed, some people doesn't woke up deruing the earthquake including me,
So I was thinking of a device to wake up people when earthquake happen.

It's impossible to make early earthquake detector, so I was thinking of a device to detect a real earthquake, and not give people heart attack for false alarms.

In my first approach I tried with keyestudio vibration sensor, but it's not accurate at all,
In my second approach I tried with MPU6050 6 Axis Acceleration and Gyro Sensor.

It works better but my problem is with the code, I don't know how to filter the false alarms, so I tried to make the code like this

#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>

// Define the MPU6050 object
MPU6050 accelgyro;

// Variables to store the acceleration values
int16_t ax, ay, az;

// Buzzer pin
int buzzerPin = 9;

// Timestamp for when the earthquake was detected
unsigned long earthquakeDetectedAt = 0;

void setup() {
  // Initialize the serial communication
  Serial.begin(9600);
  while (!Serial);

  // Initialize the MPU6050
  accelgyro.initialize();

  // Pin mode for the buzzer
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  // Read the acceleration values
  accelgyro.getMotion6(&ax, &ay, &az, 0, 0, 0);

  // Calculate the magnitude of the acceleration
  float magnitude = sqrt(pow(ax, 2) + pow(ay, 2) + pow(az, 2));

  // Check if the magnitude is greater than a threshold
  if (magnitude >= 18000) {
    // Record the timestamp for when the earthquake was detected
    earthquakeDetectedAt = millis();
  }

  // Check if an earthquake was detected recently
  if (earthquakeDetectedAt > 0 && millis() - earthquakeDetectedAt < 60000) {
    // Police siren sound
    for (int i = 0; i < 4; i++) {
      tone(buzzerPin, 1000);
      delay(100);
      noTone(buzzerPin);
      delay(100);
      tone(buzzerPin, 2000);
      delay(100);
      noTone(buzzerPin);
      delay(100);
    }

    // Wait for a certain amount of time
    delay(500);
  } else {
    // Reset the timestamp
    earthquakeDetectedAt = 0;
  }

  // Print the magnitude to the serial monitor
  Serial.println(magnitude);
  delay(100);
}

The problem is there is a lot of false alarms, I will mount the device into the wall direclty, I tried to make the sensitivity lower but still the problem is there when someone hit the wall.

What I'm trying to do is to detect the wave itself "the moving of the building", not a vibration.

Any idea how to achieve that?
Is there any real library that I can use for real earthquake?

Hello anon543

Did you made some investigation to work with mean values?

1 Like

Hi, what did you mean exactly? :slight_smile:

The MPU6050 is a very poor choice for earthquake detection. You can do much, much better with a simple DIY project, like this one: https://www.instructables.com/DIY-Seismometer/

or this one https://www.instructables.com/Extremely-Sensitive-Cheap-Homemade-Seismometer/

1 Like

Earthquakes produce two distinct waves that can be detected. One is horizontal movement and the other is vertical movement. Horizontal movement will arrive first, so that is what you need to detect. Research!

1 Like

Well, I was thinking the same, but it's so big!
I will look into that more deeply, because from what I see, seems a really good and simple approach
Thanks :slight_smile:

Oh, first time to know that, thanks sooooo much for this info, I will try to update my code

Even this https://www.instructables.com/earthquake-alarm/
Seems more accurate than my device :sweat_smile:

Good introduction to P and S waves in the Earth (not necessarily due to earthquakes):

By the way, P and S are derived from the German words for Earth motion (P) parallel to the direction of wave travel, and (S, senkrecht) for perpendicular to the direction of wave travel.

1 Like

What about using laser interferometry? Kind of like a scaled down LIGO? Have them in three directions and look for oscillations. It's just my initial thought, the actual hardware requirements and cost considerations would still have to be considered.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.