Miad Khan
Published © GPL3+

QuakeEye

Earthquake Detection and Alerting System

BeginnerWork in progress1 hour57
QuakeEye

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SparkFun Triple Axis Accelerometer and Gyro Breakout - MPU-6050
SparkFun Triple Axis Accelerometer and Gyro Breakout - MPU-6050
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
9V battery (generic)
9V battery (generic)
×1
9V to Barrel Jack Connector
9V to Barrel Jack Connector
×1
Adafruit DHT22
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

20 Pc. Jumper Wire Kit, Assorted Colors
20 Pc. Jumper Wire Kit, Assorted Colors
Breadboard, 170 Pin
Breadboard, 170 Pin
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)

Story

Read more

Schematics

Circuit Diagram

you can set up full system and wiring just by watching this.

Code

QuakeEye

C/C++
This is the main code to run this system.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <MPU6050.h>
#include <DHT.h>

#define DHTPIN 7
#define DHTTYPE DHT22
#define BUZZER 12
#define LED 13

LiquidCrystal_I2C lcd(0x27, 16, 2);
MPU6050 mpu;
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Wire.begin();
  lcd.begin(16, 2);
  lcd.backlight();

  pinMode(BUZZER, OUTPUT);
  pinMode(LED, OUTPUT);

  dht.begin();
  mpu.initialize();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("QuakeEye Ready");

for (int i = 0; i < 3; i++) {  

  lcd.setCursor(7, 1);
  lcd.print("O");
  delay(400);

  // half-close
  lcd.setCursor(7, 1);
  lcd.print("-");
  delay(200);

  lcd.setCursor(7, 1);
  lcd.print("_");
  delay(300);
}

lcd.setCursor(7, 1);
lcd.print("O"); 
delay(300);

  lcd.clear();
  unsigned long startTime = millis();
  while (millis() - startTime < 4000) {
    lcd.setCursor(0, 0);
    lcd.print("CALIBRATING.");
    delay(400);
    lcd.setCursor(0, 0);
    lcd.print("CALIBRATING..");
    delay(400);
    lcd.setCursor(0, 0);
    lcd.print("CALIBRATING...");
    delay(400);
    lcd.setCursor(0, 0);
    lcd.print("CALIBRATING   ");
    delay(400);
  }

lcd.clear();
lcd.setCursor(2, 0);  
lcd.print("CALIBRATION");
lcd.setCursor(6, 1);  
lcd.print("DONE");

  for (int i = 0; i < 2; i++) {
    digitalWrite(LED, HIGH);
    tone(BUZZER, 1000);
    delay(300);
    digitalWrite(LED, LOW);
    noTone(BUZZER);
    delay(300);
  }

  lcd.clear();
}

void loop() {
  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);

  int X = ax / 100;
  int Y = ay / 100;
  int Z = az / 100;

  int hum = (int)dht.readHumidity();
  int temp = (int)dht.readTemperature(); 

  lcd.setCursor(0, 0);
  lcd.print("X:");
  lcd.print(X);
  lcd.print(" Y:");
  lcd.print(Y);
  lcd.print(" Z:");
  lcd.print(Z);
  lcd.print(" ");

  if (X >= 0 && X <= 0 && Y >= 0 && Y <= 0 && Z >= 0 && Z <= 0) 
  {
    noTone(BUZZER);
    digitalWrite(LED, LOW);

    lcd.setCursor(0, 1);
    lcd.print("Safe ");
    lcd.print("H:");
    lcd.print(hum);
    lcd.print("% T:");
    lcd.print(temp);
    lcd.print((char)223); 
    lcd.print("C");
  } 

else {
  tone(BUZZER, 1000);  

  lcd.clear();
  lcd.setCursor(3, 0);
  lcd.print("EARTHQUAKE");

  String frames[] = {"< ALERT >", "<<ALERT>>", "> ALERT <", ">>ALERT<<"};
  int ledStates[] = {HIGH, HIGH, LOW, LOW};  // LED state for each frame

  for (int i = 0; i < 2; i++) {        // repeat animation twice
    for (int j = 0; j < 4; j++) {
      lcd.setCursor(4, 1);
      lcd.print(frames[j]);
      digitalWrite(LED, ledStates[j]);
      delay(200);
    }
  }

  noTone(BUZZER);  
  delay(100);
}

delay(500);
}

Credits

Miad Khan
1 project • 0 followers

Comments