Projects / Model seismograph

Model seismograph

A motion sensor fixed to a small table records how hard it shakes when you tap, wobble or thump the table, and shows a live trace of the size of each shake. It is a tidy way to learn how a real seismograph sees an earthquake as a wiggly line.

Intermediate1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Wire the sensor and the screen

    Both on A4 and A5, with 5V and GND.

  2. NANO

    Fix the sensor flat

    On the table with tape.

  3. NANO

    Upload the sketch

    A flat trace appears and the peak reads near 0.

  4. NANO

    Tap the table

    Small spikes appear on the trace.

  5. NANO

    Thump the table gently

    A big spike then a wobble that dies away.

  6. NANO

    Open the serial monitor

    Shake values print for each event.

  7. NANO

    Try a heavier table

    Compare how long it takes to settle.

In short

How do you build a model seismograph?

A motion sensor fixed to a small table records how hard it shakes when you tap, wobble or thump the table, and shows a live trace of the size of each shake. It is a tidy way to learn how a real seismograph sees an earthquake as a wiggly line. You need Arduino Nano, MPU6050 IMU, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 90 minutes.

Level
Intermediate
Time
About 90 min
Parts
5

Parts list

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

Wiring

FromToWhy
MPU6050 SDA and SCLNano A4 and A5I2C data and clock
MPU6050 VCC and GNDNano 5V and GNDPower for a module with a regulator
OLED SDA and SCLNano A4 and A5Shares the same I2C wires
OLED VCC and GNDNano 5V and GNDPower for a 0.96 inch module

Code

A real seismograph records how the ground moves as a wiggly line. This model does the same on a small table: the MPU6050 measures acceleration in all three directions, and the sketch works out the total, which is about 1 g at rest because of gravity. A slow average of the total follows any gentle tilt, and the wiggle on top of it is the shake. The screen scrolls that shake as a trace, 50 readings a second, with the biggest shake in the last five seconds shown at the top. Taps on the table make small spikes and a thump makes a large one, and the serial monitor prints each shake over 0.03 g, ready for a spreadsheet. Fix the sensor flat on the table with tape so it moves with it, and sit the table on a soft cloth so it can wobble. This is a model for learning only and never an earthquake warning system. Install "Adafruit SSD1306" and "Adafruit GFX" from the Library Manager. The screen and the sensor share the same two I2C wires, and the sensor usually sits at address 0x68. Try a second table with a different weight on it and compare how long the shaking lasts.

Runs on a virtual Arduino Nano 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).

// Libraries: Adafruit SSD1306 and Adafruit GFX.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const uint8_t MPU = 0x68;
const unsigned long SAMPLE_MS = 20;       // 50 readings a second

uint8_t trace[128];                       // height of each column, 0 to 40
float baseline = 1.0;                     // slow average of the total acceleration, about 1 g
float peakHold = 0;
unsigned long peakAt = 0;
unsigned long lastSample = 0;

bool readAccel(float &ax, float &ay, float &az) {
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);
  if (Wire.endTransmission(false) != 0) return false;
  if (Wire.requestFrom(MPU, (uint8_t)6, (uint8_t)true) != 6) return false;
  int16_t x, y, z;
  uint8_t h = Wire.read(); uint8_t l = Wire.read(); x = (h << 8) | l;
  h = Wire.read(); l = Wire.read(); y = (h << 8) | l;
  h = Wire.read(); l = Wire.read(); z = (h << 8) | l;
  ax = x / 16384.0; ay = y / 16384.0; az = z / 16384.0;   // in g for the default range
  return true;
}

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);                       // wake the sensor
  Wire.write(0);
  Wire.endTransmission(true);
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}

void loop() {
  unsigned long now = millis();
  if (now - lastSample < SAMPLE_MS) return;
  lastSample = now;

  float ax, ay, az;
  if (!readAccel(ax, ay, az)) { Serial.println(F("Sensor not found")); delay(500); return; }
  float mag = sqrt(ax * ax + ay * ay + az * az);
  baseline = baseline * 0.98 + mag * 0.02;           // follows slow changes such as tilting the table
  float shake = fabs(mag - baseline);                // the wiggle on top of gravity, in g

  if (shake > peakHold || now - peakAt > 5000) { peakHold = shake; peakAt = now; }
  if (shake > 0.03) { Serial.print(now); Serial.print(','); Serial.println(shake, 3); }

  memmove(trace, trace + 1, 127);                    // scroll the trace left
  int h = (int)(shake * 200.0);                      // 0.2 g fills the graph
  trace[127] = (h > 40) ? 40 : h;

  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setTextSize(1);
  oled.setCursor(0, 0);
  oled.print(F("Peak (5 s): "));
  oled.print(peakHold, 2);
  oled.print(F(" g"));
  for (uint8_t x = 0; x < 128; x++) oled.drawFastVLine(x, 63 - trace[x], trace[x] + 1, SSD1306_WHITE);
  oled.display();
}

Test checklist

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

CheckExpected
Still tableFlat trace, peak near 0
TapA short spike
WobbleA swinging trace that dies away
PeakHolds for five seconds
Serial monitorPrints time and shake size

If it does not work

Sensor not found message

Check SDA, SCL and power, and the module address.

Trace always full

Check the sensor is fixed flat and still when you start.

Trace never moves

Increase the multiplier 200 in the code.

Blank screen

Check the OLED wires and try address 0x3D.

Sensor gets warm

Check it is on 5V only if its module has a regulator.

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

Ask Lark AI

Common questions

What parts do I need for the model seismograph?

Arduino Nano, MPU6050 IMU, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the model seismograph take to build?

About 90 minutes for a intermediate maker, in 7 steps.

How do I know the model seismograph works?

Still table: Flat trace, peak near 0. Tap: A short spike. Wobble: A swinging trace that dies away.

Sensor not found message: what should I check?

Check SDA, SCL and power, and the module address.

Trace always full: what should I check?

Check the sensor is fixed flat and still when you start.

Trace never moves: what should I check?

Increase the multiplier 200 in the code.

Blank screen: what should I check?

Check the OLED wires and try address 0x3D.