Journal

How to Install an Earthquake Detection System with MPU6050 and ESPHome at Home

วิธีติดตั้งระบบตรวจจับแผ่นดินไหวด้วย MPU6050 และ ESPHome ทำเองได้ที่บ้าน

May 16, 2026 · 2 min read
How to Install an Earthquake Detection System with MPU6050 and ESPHome at Home

What Is the MPU6050?

The MPU6050 is a sensor chip manufactured by InvenSense that measures 6-axis motion, including a 3-axis accelerometer and a 3-axis gyroscope. It offers 16-bit resolution, a sampling rate up to 1,000 Hz, and supports I2C and SPI communication. Priced at around 50 to 150 baht in Thailand, it is well suited for earthquake vibration detection because it simultaneously captures acceleration changes across the X, Y, and Z axes.

What Is ESPHome and Why Use It?

ESPHome is open-source firmware for ESP32 and ESP8266 boards designed for seamless Home Assistant integration. Configuration is done through readable YAML files without writing any C++ code. ESPHome includes native MPU6050 component support, making the setup achievable in just a few configuration lines.

Required Hardware

The core components are one MPU6050, one ESP32 or ESP8266 NodeMCU board, four male-to-female Dupont jumper wires, one micro USB cable, and a computer running Home Assistant. All components are available at local electronics shops or on Shopee and Lazada for a total of under 500 baht.

Wiring the MPU6050 to ESP32 or ESP8266

For ESP32: connect MPU6050 VCC to ESP32 3.3V, GND to GND, SDA to GPIO21, and SCL to GPIO22. For ESP8266 NodeMCU: use SDA on GPIO4 (D2) and SCL on GPIO5 (D1), with VCC and GND connected the same way. Always verify the pinout of your specific board before making connections.

Installing ESPHome and Creating a New Device

Open Home Assistant, navigate to Settings, select Add-ons, and install the ESPHome Add-on from the Add-on Store. Once installed, open the ESPHome Dashboard, create a new device, name it, select your board type, and add the YAML configuration for MPU6050. Specify the I2C pins matching your wiring, set the MPU6050 address to 0x68, define sensor names for Accel X, Accel Y, and Accel Z, and set an update interval such as 100ms. Then click Install and ESPHome will automatically upload the firmware to the board via USB.

Configuring Home Assistant Automations

Once the board is online, Home Assistant will detect the sensors automatically through Auto-Discovery. Create an automation using the Numeric State of any acceleration axis exceeding a threshold such as 0.5g as the Trigger, and define Actions to send notifications to mobile devices, activate emergency lights, and unlock exit doors.

Test the system by gently shaking the sensor to confirm the automation fires correctly. Adjust the threshold based on the actual noise environment around your installation.

Advanced Techniques

For multi-story homes, install separate MPU6050 sensors per floor, each reporting independently to Home Assistant to identify which area experiences the strongest vibration. For data analysis, use Node-RED to build real-time dashboard graphs, or log readings to InfluxDB and Grafana for long-term trend analysis. Data can also be sent to Google Sheets via Google Apps Script to maintain a permanent event log.

Questions & answers

Is the MPU6050 suitable for detecting earthquakes?
Yes, with 16-bit resolution and 1,000 Hz sampling rate, it is sufficient to detect vibration at earthquake-relevant intensities, particularly from 3.5 magnitude upward.
Do I need to write code to install this system?
No. ESPHome uses simple YAML configuration files, and Home Assistant Auto-Discovery detects the sensor automatically. No C++ or Python coding is required.
What is the wiring difference between ESP32 and ESP8266?
ESP32 uses SDA on GPIO21 and SCL on GPIO22. ESP8266 NodeMCU uses SDA on GPIO4 (D2) and SCL on GPIO5 (D1). Always verify your specific board pinout before connecting wires.
How can I test the system without waiting for an actual earthquake?
Gently shake the sensor by hand and check whether the Home Assistant automation triggers. You can also temporarily lower the threshold for testing, then restore it after confirming the system works correctly.
Can I install multiple sensors in a multi-story home?
Yes, install separate MPU6050 sensors per floor or zone, each connected to its own ESP32 and all linked to the same Home Assistant instance, enabling independent vibration monitoring by area.

Related reading