Projects / Earthquake shake logger

Earthquake shake logger

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ESP32MICROSDS323113:03

    Wire the sensor, clock and card

    Connect them as in the table and set the DS3231 time.

  2. ESP32

    Check the readings

    Print the high-passed value and confirm it sits close to zero when still.

  3. ESP32

    Fix the sensor down

    Bolt it flat on a concrete floor with the Z axis up.

  4. ESP32

    Test with a tap

    Stamp near the sensor and check a QUAKE.CSV entry appears with the time.

  5. ESP32

    Let it run

    Leave it for a few days and look at how often it triggers.

  6. ESP32

    Compare

    Match entries against known earthquake times and ignore the ones from footsteps.

In short

How do you build an earthquake shake logger?

An ADXL345 accelerometer bolted to the floor records vibrations, and logs and timestamps any shaking well above the background level. It is a hobby logger, not a warning system. You need ESP32 DevKit V1, ADXL345 accelerometer, MicroSD Card Module, DS3231 RTC module and Active buzzer 5 V. It takes 6 steps and about 180 minutes.

Level
Intermediate
Time
About 180 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
ADXL345 VCC, GNDESP32 3V3, GNDPower
ADXL345 SDA, SCLESP32 GPIO21, GPIO22I2C
DS3231 SDA, SCLESP32 GPIO21, GPIO22I2C, same bus
DS3231 VCC, GNDESP32 3V3, GNDPower
SD module CSESP32 GPIO5Chip select
SD module SCK, MISO, MOSIESP32 GPIO18, GPIO19, GPIO23SPI
SD module VCC, GNDESP32 5V (VIN), GNDPower (module has a regulator)
Active buzzer +ESP32 GPIO4Beeps when an event is logged
Active buzzer -ESP32 GNDReturn

Code

Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module". Install "Adafruit ADXL345", "Adafruit Unified Sensor" and "RTClib". Bolt the sensor to a solid floor or foundation away from foot traffic and machinery. Footsteps and doors will trigger it too, so compare the logged events against the times of earthquakes listed by your national seismology service. This is a hobby logger, not an alarm, and it cannot warn you of an earthquake.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <RTClib.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

Adafruit_ADXL345_Unified accel(12345);
RTC_DS3231 rtc;
const byte BUZZER = 4;
const int RATE = 100;                        // samples per second
const int PRE = 5 * RATE, POST = 5 * RATE;   // 5 s before and after an event
float ring[PRE];                             // high-passed magnitude, in m/s2
int head = 0;
float grav = 9.81, noise = 0.02;             // slow gravity estimate and noise floor
unsigned long nextTick;

void logEvent(float peak) {
  DateTime n = rtc.now();
  File f = SD.open("QUAKE.CSV", FILE_WRITE);
  if (!f) return;
  f.print("EVENT,"); f.print(n.timestamp()); f.print(",peak "); f.println(peak, 3);
  for (int i = 0; i < PRE; i++) { f.println(ring[(head + i) % PRE], 4); }   // 5 s before
  for (int i = 0; i < POST; i++) {                                          // 5 s after
    while (micros() < nextTick) {}
    nextTick += 1000000UL / RATE;
    sensors_event_t e; accel.getEvent(&e);
    float mag = sqrt(e.acceleration.x * e.acceleration.x + e.acceleration.y * e.acceleration.y + e.acceleration.z * e.acceleration.z);
    f.println(mag - grav, 4);
  }
  f.close();
  digitalWrite(BUZZER, HIGH); delay(150); digitalWrite(BUZZER, LOW);
}

void setup() {
  pinMode(BUZZER, OUTPUT);
  Wire.begin(21, 22);
  accel.begin();
  accel.setRange(ADXL345_RANGE_2_G);
  accel.setDataRate(ADXL345_DATARATE_100_HZ);
  rtc.begin();
  SD.begin(5);
  nextTick = micros();
}

void loop() {
  while (micros() < nextTick) {}
  nextTick += 1000000UL / RATE;
  sensors_event_t e; accel.getEvent(&e);
  float mag = sqrt(e.acceleration.x * e.acceleration.x + e.acceleration.y * e.acceleration.y + e.acceleration.z * e.acceleration.z);
  grav = 0.999 * grav + 0.001 * mag;         // slow average removes gravity and tilt
  float hp = mag - grav;
  ring[head] = hp; head = (head + 1) % PRE;
  noise = 0.995 * noise + 0.005 * fabs(hp);  // running background level
  if (fabs(hp) > 5.0 * noise + 0.05) logEvent(fabs(hp));
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Sitting stillNo events
Stamping near itOne event logged with a beep
Quiet nightA few events or none
Card in a PCQUAKE.CSV with timestamped 10 second windows

If it does not work

Events every second

The threshold is too low or the sensor is loose. Fix it down and raise 0.05.

Never triggers

Lower the threshold, and check the sensor data rate setting.

Writing fails

Check the SD card is FAT32 and the CS pin.

Time stamps wrong

Set the DS3231 and check its coin cell.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the earthquake shake logger?

ESP32 DevKit V1, ADXL345 accelerometer, MicroSD Card Module, DS3231 RTC module and Active buzzer 5 V.

How long does the earthquake shake logger take to build?

About 180 minutes for a intermediate maker, in 6 steps.

How do I know the earthquake shake logger works?

Sitting still: No events. Stamping near it: One event logged with a beep. Quiet night: A few events or none.

Events every second: what should I check?

The threshold is too low or the sensor is loose. Fix it down and raise 0.05.

Never triggers: what should I check?

Lower the threshold, and check the sensor data rate setting.

Writing fails: what should I check?

Check the SD card is FAT32 and the CS pin.

Time stamps wrong: what should I check?

Set the DS3231 and check its coin cell.