Earthquake Detector using Arduino and MPU-6050

Earthquake Detector using Arduino and MPU6050 sensor: Earthquake detector is a device that detects earthquake shocks. According to research, approximately 800,000 earthquakes occurs in a year which kills so many lives and destroys buildings. Our project is a small effort to overcome the loss which occurs due to the earthquake. This detector can detect the minor shocks and alarm you to evacuate to a safe place. The most important component of this detector is MPU 6050 module which we will talk later. Arduino is the brain of this detector, LCD is used to display message and Led and buzzer is used as indicators.

Block Diagram Earthquake Detector using Arduino Earthquake Detector using Arduino block diagram

Components Required

  • ArduinoUno: We used Arduino Uno because is cheap and it fits perfect for this project as we need two analog pins and eight digital pins. It is easy to program and have a penalty of memory to store program.
  • MPU6050: MPU6050 is 6 Axis Accelerometer and gyroscope. It is generally a motion tracking device. It is also capable of measuring temperature. It consumes less power and very cheap in price.

Here are some feature MPU6050

  • Gyroscope operating current: 3.6mA.
  • Accelerometer normal operating current: 500µA.
  • Standby current: 5µA.
  • Operating voltages lies between 2.37v to 3.46v
  • Improved low-frequency noise performance.
  • Digital-output temperature sensor.

Pin description of MPU6050 module:

  1. Vcc: Supply voltages of 3.3 to this pin.
  2. GND: This pin connected to ground.
  3. SCL: I2C Serial Clock Pin.
  4. SDA: I2C Serial Data Pin.
  5. XDA: I2C Master Data pin for an external sensor.
  6. XCL: I2C Master Clock pin for an external sensor.
  7. AD0: I2C Slave Address LSB.
  8. INT: Interrupt digital output pin.
  • 16×2 LCD: LCD is used to show alphanumeric characters. It has total 16 pins. A 10K ohm potentiometer is connected with pin three to set the contrast of the LCD. It also contains a backlight LED. In this project LCD, we use is 16×2 which means we can display 16 characters in two lines. In this project, LCD is used to show whether the shocks are detected or not.
  • Led: A red led is used to indicate that earthquake shocks are detected and the red color is also representing danger.
  • Buzzer: A buzzer generates a high sound which alarms the people that earthquake shocks are detected.
  • Resistor and some jumper wires

Circuit Diagram of Earthquake Detector using Arduino Earthquake Detector using Arduino circuit diagram

Working of Earthquake Detector using Arduino block diagram

The Arduino first of all initialize MPU 6050. Check the sleep mode and a clock signal from module then started reading the values. There are maximum and minimum values are declared in the code it checks if the value is greater or smaller than the desired values then it starts the buzzer, led and display message “***Earthquake***”o n the LCD. If the values are normal then it does nothing.

Implementation of Earthquake Detector using Arduino

Earthquake detector using Arduino

Serial Plotter for Earthquake Detector using Arduino


Code of Earthquake Detector using Arduino

#include <LiquidCrystal.h>

#include <Wire.h>

#include <MPU6050.h>

#define minval -5

#define maxval 3

MPU6050 mpu;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()

{   lcd.begin(16, 2);




    lcd.print("   EarthQuake ");

    lcd.setCursor(0, 1);

    lcd.print("   Detector");

    delay (2000);


  // Initialize MPU6050

  Serial.println("Initialize MPU6050");

  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

  { Serial.println("Could not find a valid MPU6050 sensor, check wiring!");



  // Check settings



void checkSettings()



  Serial.print(" * Sleep Mode:        ");

  Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");

  Serial.print(" * Clock Source:      ");


  {case MPU6050_CLOCK_KEEP_RESET:     Serial.println("Stops the clock and keeps the timing generator in reset"); break;

    case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break;

    case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break;

    case MPU6050_CLOCK_PLL_ZGYRO:      Serial.println("PLL with Z axis gyroscope reference"); break;

    case MPU6050_CLOCK_PLL_YGYRO:      Serial.println("PLL with Y axis gyroscope reference"); break;

    case MPU6050_CLOCK_PLL_XGYRO:      Serial.println("PLL with X axis gyroscope reference"); break;

    case MPU6050_CLOCK_INTERNAL_8MHZ:  Serial.println("Internal 8MHz oscillator"); break;


  Serial.print(" * Gyroscope:         ");


  {case MPU6050_SCALE_2000DPS:        Serial.println("2000 dps"); break;

    case MPU6050_SCALE_1000DPS:        Serial.println("1000 dps"); break;

    case MPU6050_SCALE_500DPS:         Serial.println("500 dps"); break;

    case MPU6050_SCALE_250DPS:         Serial.println("250 dps"); break:}

  Serial.print(" * Gyroscope offsets: ");


  Serial.print(" / ");


  Serial.print(" / ");



void loop()

{   Vector rawGyro = mpu.readRawGyro();

  Vector normGyro = mpu.readNormalizeGyro();

  Serial.print(" Xraw = ");


  Serial.print(" Yraw = ");


  Serial.print(" Zraw = ");


if(normGyro.XAxis > maxval || normGyro.XAxis < minval && normGyro.YAxis > maxval || normGyro.YAxis  < minval && normGyro.ZAxis > maxval || normGyro.ZAxis  < minval)

{ digitalWrite(7,HIGH);








  delay (1000);




  Serial.print(" Xnorm = ");


  Serial.print(" Ynorm = ");


  Serial.print(" Znorm = ");



video lecture Earthquake Detector using Arduino

13 thoughts on “Earthquake Detector using Arduino and MPU-6050”

  1. Hi Bilal,
    Just saying hi to a like mind.
    Where are you?
    We, Fay and I, are in the Pacific North West.
    I am relearning programming in C after a lifetime doing eng/physics.

    • Jordan, it is a potentiometer. Take a look at the 16×2 LCD link near the top of this article. It shows more information. That link indicates it is a 10k pot. I hope that helps!

  2. With this source code i have error that ” normGyro was not declered in this scope”. Which way do i solve this?Please!

  3. Good morning sir.
    Can you help me do this detector.
    I am currently a school Disaster risk reduction coordinator and im doing a thing like this. Hehe.

  4. hello everyone..
    i tried everything .. 12cdev, ide 1.6.9, ide 1.0.1, ide 1.8.8.. just one message show ..error.. ‘class MPU6050’ has no member named ‘begin, initialize is not alternative begin also. i use Arduino uno china .
    please give me full process for uploading this software. if u can make a video (full process for uploading this software) mpu6050 it will be viral…

    my email id is: [email protected]

  5. hello guys
    i tried everything .. 12cdev, ide 1.6.9, ide 1.0.1, ide 1.8.8.. just one message show ..error.. ‘class MPU6050’ has no member named ‘begin, initialize is not alternative begin also. i use Arduino uno
    please give me full process for uploading this software. i

    my email id is: [email protected]


Leave a Comment