How to Build an Arduino‑Powered Earthquake Detector
Ever wondered if you could turn a cheap microcontroller into a miniature seismometer? The answer is a resounding yes. With a handful of components and a dash of curiosity, you can craft a sensor that trembles at the slightest ground motion—perfect for hobbyists, teachers, or anyone fascinated by the hidden rhythms of our planet.
What You’ll Need
- Arduino Uno or compatible board – the brain of the project.
- MPU‑6050 6‑axis accelerometer – senses motion on three axes and feeds raw data to the Arduino.
- Breadboard and jumper wires – for quick, solder‑free connections.
- USB cable – to power the board and upload code.
- Optional: LCD display or LEDs – for visual alerts.
- Enclosure (plastic box or 3‑D printed case) – protects the electronics from dust.
If you’re short on budget, a recycled Arduino clone works just as well, and the MPU‑6050 can be purchased for under $5.
Understanding the Basics
The MPU‑6050 combines a three‑axis accelerometer with a gyroscope. For earthquake detection we only care about the accelerometer portion, which reports acceleration in g‑units (gravity). When the ground shakes, those values deviate from the static 1 g that points straight down.
Why not use a dedicated seismometer? Professional devices are calibrated for sub‑micrometer movements—a level beyond what hobbyist hardware can reliably catch. That’s fine; our goal is to spot noticeable tremors, not to replace scientific stations.
Wiring the Sensor to the Arduino
Follow this quick map:
- VCC of MPU‑6050 → 5 V on Arduino
- GND → GND
- SCL → A5 (Arduino Uno I²C clock)
- SDA → A4 (Arduino Uno I²C data)
- INT (interrupt) – optional, can be left unconnected for a simple read loop.
Once the wires are snug on the breadboard, plug the Arduino into your computer. You’re ready to talk to the sensor.
Programming the Detector
Open the Arduino IDE, install the MPU6050 library (by Jeff Rowberg) via the Library Manager, then paste the sketch below. It reads acceleration, filters out background noise, and triggers an alert when a threshold is crossed.
#include <Wire.h>#include <MPU6050.h>
MPU6050 accelgyro;
const int ledPin = 13; // built‑in LED as indicator
const float threshold = 0.3; // g‑units beyond normal 1 g
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
Wire.begin();
accelgyro.initialize();
if (!accelgyro.testConnection()) {
Serial.println("MPU6050 connection failed");
while (1);
}
Serial.println("Earthquake detector ready");
}
void loop() {
int16_t ax, ay, az;
accelgyro.getAcceleration(&ax, &ay, &az);
// Convert to g (assuming default ±2 g range)
float gx = ax / 16384.0;
float gy = ay / 16384.0;
float gz = az / 16384.0;
// Simple magnitude calculation
float magnitude = sqrt(gx*gx + gy*gy + gz*gz) - 1.0; // subtract 1 g gravity
if (abs(magnitude) > threshold) {
digitalWrite(ledPin, HIGH);
Serial.print("Shake detected! Mag: ");
Serial.println(magnitude, 3);
} else {
digitalWrite(ledPin, LOW);
}
delay(100);
}
The code is deliberately straightforward. It reads raw values, converts them, and checks whether the combined acceleration exceeds threshold. Adjust that number—lower for more sensitivity, higher to avoid false alarms.
Calibrating for Real‑World Use
Place the assembled board on a stable surface and let it sit for a minute. Watch the serial monitor; it should hover close to zero after the “‑1 g” correction. If you notice a steady drift, tweak the threshold or add a moving average filter.
For a more robust setup, consider:
- Enclosing the sensor in a silicone gel to dampen high‑frequency noise.
- Sampling at a higher rate (e.g., 200 Hz) and applying a low‑pass filter.
- Logging data to an SD card for post‑event analysis.
Adding Visual or Audible Alerts
Beyond the built‑in LED, many makers attach a buzzer or an LCD screen. A simple piezo buzzer wired to pin 8 can replace the LED line with:
tone(8, 1000, 200); // 1 kHz beep for 200 msIf you prefer a text display, a 16×2 LCD (via I²C) can show the current magnitude, giving a quick readout of how strong the tremor feels.
Putting It All Together
When you’re satisfied with the code and the housing, mount the detector on a sturdy base—perhaps a wooden block bolted to the floor. Anything that moves independently will generate false positives.
Now, when the earth shivers, your Arduino will flash, beep, or print a line of data, letting you know that something’s happening beneath your feet.
Expanding the Project
Want to go further? Here are a few ideas that hobbyists often explore:
- Wireless reporting – use an ESP‑01 module to push alerts to a phone.
- Network of sensors – place several detectors around a house and compare timestamps to locate the epicenter.
- Integration with Home Assistant – trigger smart lights or send an email when shaking exceeds a set level.
Each addition adds complexity, but the core principle stays the same: capture acceleration, filter out noise, and react when the signal crosses a meaningful threshold.
With a modest budget and a sprinkle of tinkering, you’ve just built a functional seismic sensor. Whether it ends up on a school science fair table or tucked under a desk, it’s a tangible reminder that even simple electronics can listen to the planet’s pulse.