Hi from Turkey
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?