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.
