Contents — 26 sections
Project Overview
A community seismic node that recognises the first faint tremor of an earthquake and triggers a fast local shake alert — buying seconds before the strong shaking arrives.
Earthquake early warning is a race against a wave. When a fault ruptures, it sends out two kinds of seismic waves: a fast, weak P-wave that arrives first and does little damage, and a slower, violent S-wave (and surface waves) that arrive seconds to tens of seconds later and cause the destruction. If a sensor near the source detects the P-wave and immediately shouts a warning that travels at the speed of electronics — far faster than the S-wave travels through rock — places further away can get a few seconds to a minute of notice before the strong shaking hits. Those seconds are enough to stop trains, halt surgeries, open elevator doors, shut gas valves, and let people drop, cover and hold. This project builds one node of a community network that plays that game.
The heart of it is an accelerometer watching the ground constantly and an algorithm that can tell a genuine seismic P-wave from the endless background of a truck rumbling past, a door slamming, or someone bumping the bench. The classic method is STA/LTA — comparing a short-term average of the vibration energy to a long-term average — which fires when the signal suddenly jumps above its recent background, the signature of a wave arriving. On a P-wave detection the node instantly emits an alert; when many nodes are networked, agreement between several nearby nodes confirms a real earthquake (not one person's washing machine) and the network estimates where and how strong it is, issuing warnings outward ahead of the damaging waves.
A single hobby node is not a seismograph and cannot, alone, warn anyone reliably — false alarms from local noise would make it useless. Its value is entirely in the network and the honesty of the trigger: cheap MEMS accelerometers, densely deployed and cross-confirmed, can genuinely contribute to early warning, as community seismic projects have shown. So this node is designed to be a good citizen of such a network — a clean, well-characterised trigger with a sensible noise floor, accurate timing, and immediate local action (a loud shake alert) combined with networked confirmation. It is explicit that reliable warning is a system property, not a single-device one, and that it complements rather than replaces national seismic networks — but as a node you can build and run, it turns the abstract idea of earthquake early warning into something concrete on your own bench.
What this project does
- Continuously monitors ground vibration with a MEMS accelerometer
- Detects a seismic P-wave arrival with an STA/LTA trigger
- Rejects everyday noise (traffic, footsteps, bumps) below the trigger
- Emits an immediate local shake alert on detection
- Contributes to networked confirmation and location by many nodes
- Timestamps events accurately for cross-node correlation
- Complements, does not replace, official seismic networks
Real-World Applications
| Setting | How it is used |
|---|---|
| Community earthquake early warning | Dense citizen networks in seismic regions contributing detections that, cross-confirmed, deliver seconds of warning to a wider area. |
| Schools, hospitals and offices | A local node that sounds a drop-cover-hold alert and can trigger automatic safety actions the moment shaking is detected. |
| Critical infrastructure triggers | Fast local shut-off signals for gas, elevators or machinery on confirmed strong shaking. |
| Education and research | A hands-on platform for teaching seismology, detection algorithms and the physics of earthquake early warning. |
Deployment contexts where a build of this kind earns its keep.
Features & Capabilities
- STA/LTA P-wave trigger — the classic seismic detection method
- Noise-floor characterisation so local bumps do not false-trigger
- Immediate local drop-cover-hold alert on detection
- Networked cross-confirmation to reject single-node false alarms
- Accurate timing for multi-node location and magnitude estimation
- Honest framing: warning is a network property, not one device
- Cheap, dense, community-deployable seismic node
Difficulty, Time & Required Skills
| Attribute | Value |
|---|---|
| Difficulty level | Advanced |
| Estimated completion time | 12–20 hours |
| Indicative build cost | ₹2,500 – ₹4,500 |
| Primary discipline | Environment |
| Reference platform | ESP32 DevKit V1 (ESP-WROOM-32) |
Skills you should have (or will pick up)
- Reading a MEMS accelerometer at a steady sample rate
- Implementing the STA/LTA detection algorithm and setting its parameters
- Characterising and rejecting environmental noise
- Accurate timekeeping and networked event correlation
- Designing immediate local alerts and safe automatic actions
Bill of Materials
Every part below is commonly available from Indian and international hobby-electronics suppliers. Prices are indicative 2026 retail figures in Indian rupees and will drift — treat them as a budgeting guide, not a quotation.
| Component | Key specification | Qty | Approx. cost |
|---|---|---|---|
| ESP32 DevKit V1 (ESP-WROOM-32) Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly. | Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC | 1 | ₹450 |
| MPU-6050 6-axis IMU Gyro bias drifts with temperature — re-zero at boot while the device is still. | 3-axis gyro ±250–2000 °/s, 3-axis accel ±2–16 g, 16-bit ADC, on-chip DMP | 1 | ₹190 |
| ADXL345 3-axis accelerometer Built-in activity/free-fall interrupts let the MCU deep-sleep until something moves. | ±2/4/8/16 g, 13-bit, 0.004 g/LSB, tap and free-fall interrupts, 3200 Hz | 1 | ₹220 |
| Active piezo buzzer 5 V Active buzzers make tone on DC; passive ones need a PWM carrier. | 85 dB at 10 cm, 2.3 kHz resonance, 12 mm diameter | 1 | ₹25 |
| 0.96″ SSD1306 OLED display Static images burn in — invert or scroll the screen periodically. | 128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C | 1 | ₹250 |
| DS3231 precision RTC + CR2032 backup Vastly better than DS1307; some boards trickle-charge a non-rechargeable cell — cut that resistor. | ±2 ppm (±1 min/year), temperature-compensated crystal, alarms, 32 kHz out | 1 | ₹180 |
| 5 V 3 A regulated SMPS adapter Measure the real output — many "3 A" adapters sag below 4.7 V at 2 A. | 100–240 VAC in, 5 V ±5 % out, 3 A, short-circuit and over-voltage protection | 1 | ₹350 |
| High-sensitivity accelerometer Lower noise floor = smaller detectable quakes; upgrade for real use | MPU-6050/ADXL345 for a starter; a low-noise MEMS (e.g. ADXL355-class) for real sensitivity | 1 | ₹400 |
| Rigid mounting plate + fixings A firm coupling to the ground is essential | Bolts the sensor solidly to a floor slab or structural wall | 1 | ₹150 |
| GPS time module (optional) Or discipline the RTC from NTP; timing accuracy drives location | For sub-second synchronised timestamps across nodes | 1 | ₹500 |
| Loud alert + strobe | Audible/visual drop-cover-hold alert for the room | 1 | ₹300 |
Estimated total: ₹3,015, excluding tools, shipping and consumables.
Tools and consumables
- Soldering iron (temperature controlled, 350 °C) with 0.8 mm 60/40 or lead-free solder
- Digital multimeter — continuity, DC volts and current ranges
- Wire strippers, flush cutters and a small set of precision screwdrivers
- Heat-shrink tubing and a heat gun (or a lighter, carefully)
- A laptop with a USB port and the toolchain listed above
Hardware Specifications
| Part | Specification | Supply | Interface | Reference |
|---|---|---|---|---|
| ESP32 DevKit V1 (ESP-WROOM-32) | Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC | 3.3 V logic / 5 V USB | UART, SPI, I²C, I²S, CAN, PWM | Datasheet |
| MPU-6050 6-axis IMU | 3-axis gyro ±250–2000 °/s, 3-axis accel ±2–16 g, 16-bit ADC, on-chip DMP | 2.375–3.46 V (module 5 V tolerant) | I²C (0x68/0x69) | Datasheet |
| ADXL345 3-axis accelerometer | ±2/4/8/16 g, 13-bit, 0.004 g/LSB, tap and free-fall interrupts, 3200 Hz | 2.0–3.6 V | I²C / SPI | Datasheet |
| Active piezo buzzer 5 V | 85 dB at 10 cm, 2.3 kHz resonance, 12 mm diameter | 3–5 V | Digital / PWM | Datasheet |
| 0.96″ SSD1306 OLED display | 128 × 64 monochrome, 1.3–3.3 V logic, 100 kHz–400 kHz I²C | 3.3–5 V | I²C (0x3C) | Datasheet |
| DS3231 precision RTC + CR2032 backup | ±2 ppm (±1 min/year), temperature-compensated crystal, alarms, 32 kHz out | 2.3–5.5 V | I²C (0x68) | Datasheet |
| 5 V 3 A regulated SMPS adapter | 100–240 VAC in, 5 V ±5 % out, 3 A, short-circuit and over-voltage protection | 5 V | DC barrel / USB | Datasheet |
Consolidated electrical and interface specifications for every active part in the build.
Power Budget & Supply Sizing
Add up the typical active current of every part, then size the supply with at least 50 % headroom so transmit bursts and motor inrush never brown out the controller.
| Load | Supply rail | Typical current (mA) | Notes |
|---|---|---|---|
| ESP32 DevKit V1 (ESP-WROOM-32) | 3.3 V logic / 5 V USB | 160 | Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly. |
| MPU-6050 6-axis IMU | 2.375–3.46 V (module 5 V tolerant) | 3.9 | Gyro bias drifts with temperature — re-zero at boot while the device is still. |
| ADXL345 3-axis accelerometer | 2.0–3.6 V | 0.14 | Built-in activity/free-fall interrupts let the MCU deep-sleep until something moves. |
| Active piezo buzzer 5 V | 3–5 V | 30 | Active buzzers make tone on DC; passive ones need a PWM carrier. |
| 0.96″ SSD1306 OLED display | 3.3–5 V | 20 | Static images burn in — invert or scroll the screen periodically. |
| DS3231 precision RTC + CR2032 backup | 2.3–5.5 V | 0.2 | Vastly better than DS1307; some boards trickle-charge a non-rechargeable cell — cut that resistor. |
| 5 V 3 A regulated SMPS adapter | 5 V | 3000 | Measure the real output — many "3 A" adapters sag below 4.7 V at 2 A. |
Summed typical draw is 3214.24 mA. With a 1.5× design margin the supply should deliver at least 4900 mA continuously at the stated rail voltage.
Software Requirements & Development Environment
Reference toolchain: Arduino IDE 2.3.x with the ESP32 board package 3.x (or PlatformIO on VS Code). Anything newer normally works; anything older may lack the board definitions used here.
- Install the Arduino IDE 2.3.x (or PlatformIO if you prefer a real editor and dependency locking).
- Add
https://espressif.github.io/arduino-esp32/package_esp32_index.jsonunder File → Preferences → Additional Board Manager URLs, then install esp32 from the Boards Manager. - Set the correct port under Tools → Port. On Linux add yourself to the
dialoutgroup:sudo usermod -aG dialout $USERand log out and back in. - Open the Serial Monitor at 115200 baud — every sketch here logs its state there.
- Keep File → Preferences → Show verbose output during: compilation switched on while you are debugging build errors.
Required libraries
| Library | Why it is needed | Install |
|---|---|---|
| WiFi (ESP32 core) bundled | Station/AP connection management for the ESP32. | Bundled with the ESP32 Arduino core |
| PubSubClient 2.8 | Lightweight MQTT 3.1.1 client for constrained devices. | Library Manager → "PubSubClient" by Nick O'Leary |
| MPU6050_light / Adafruit MPU6050 1.3.x | IMU register access, calibration and complementary-filter angles. | Library Manager → "MPU6050_light" by rfetick |
| Adafruit SSD1306 + GFX 2.5.x | Framebuffer and text/graphics primitives for the OLED. | Library Manager → "Adafruit SSD1306" |
| NTPClient / configTime bundled | Wall-clock time from an NTP server for timestamping. | Bundled (`configTime()` on ESP32) |
| ArduinoJson 7.x | Zero-allocation JSON serialisation and parsing. | Library Manager → "ArduinoJson" by Benoit Blanchon |
| Preferences (NVS) bundled | Wear-levelled key/value storage in ESP32 flash for settings. | Bundled with the ESP32 core |
Block Diagram
The block diagram shows the functional decomposition of the system — what senses, what decides, what acts, and where the data ends up.
Circuit Diagram & Wiring
Every signal line in the build is shown below, followed by a pin-by-pin connection table you can work through with a multimeter in hand.
| Peripheral | Peripheral pin | Controller pin | Signal |
|---|---|---|---|
| Accelerometer | SDA/SCL | GPIO 21/22 | Triaxial ground motion (I²C) |
| Accelerometer | INT | GPIO 34 | Data-ready interrupt |
| DS3231 RTC / GPS | SDA/SCL / UART | GPIO 21-22 / 16-17 | Accurate timestamps |
| Buzzer + strobe | IN | GPIO 13 | Local shake alert |
| OLED | SDA/SCL | GPIO 21/22 | Status/live seismogram |
| Wi-Fi | on-chip | — | Networked detection reporting |
| 5V supply | +/– | 3V3 reg | Mains-powered (fixed install) |
Wire one row at a time and tick it off — most "it does not work" reports trace back to a single swapped pair.
Wiring explanation
- Bolt the accelerometer rigidly to a structural floor or wall so it moves with the building; a sensor on a wobbly bench measures the bench, not the earthquake.
- Sample the accelerometer at a steady, known rate (e.g. 100 Hz) using its data-ready interrupt so the STA/LTA windows are correctly timed.
- Give the node accurate time — GPS-disciplined or NTP-disciplined RTC — because multi-node location depends on precise arrival timestamps.
- Keep the sensor away from local vibration sources (HVAC, machinery, foot traffic) that would raise its noise floor and cause false triggers.
- Wire the alert loud and unmissable; on a confirmed strong event it must reliably prompt drop-cover-hold.
System Architecture
Read the stack from the bottom up: physical hardware, the firmware that drives it, the transport that moves data off the device, and the software a human actually looks at.
Working Principle
Earthquake early warning exploits the gap between two waves and the gap between rock and radio. A rupture emits a fast, low-amplitude P-wave (compressional, ~6–8 km/s) ahead of the slower, destructive S-wave and surface waves (~3–4 km/s). A sensor close to the epicentre feels the P-wave first; if it instantly sends an alert electronically, that alert outruns the still-travelling S-wave to more distant places. The warning time is essentially the difference in travel times — small near the epicentre, larger far from it — which is why dense networks and fast triggers matter: every fraction of a second shaved off detection is added to someone's warning.
The detection algorithm at the core is STA/LTA, the workhorse of seismology. It maintains a Short-Term Average of the signal's energy (over, say, the last second) and a Long-Term Average (over the last tens of seconds), and computes their ratio. In quiet times the two are similar and the ratio hovers near one; when a wave arrives, the short-term energy jumps while the long-term average still reflects the quiet background, so the ratio spikes. A trigger fires when the ratio crosses a threshold, and de-triggers when it falls back. The beauty of the method is that it is self-scaling: it responds to a sudden change relative to recent background, so it works whether the site is inherently quiet or a bit noisy, and it adapts as conditions drift.
The hard part on a cheap node is rejecting the non-earthquake world. A passing truck, a slammed door, footsteps, or someone knocking the desk all produce transients that can spike STA/LTA just like a P-wave. Several things help: characterising the site's noise floor and setting the threshold above it; requiring the trigger to persist and to show up across all three axes in a way consistent with ground motion rather than a single-axis tap; and, decisively, networked cross-confirmation. A real earthquake shakes many nearby nodes within a physically-consistent time pattern; one person's washing machine shakes exactly one node. So the network treats a lone detection as suspect and a coincident cluster of detections, arriving in a pattern consistent with a wave sweeping across the array, as a confirmed event — which also lets it estimate the epicentre (from the relative arrival times) and a rough magnitude (from the amplitudes).
This is why the design insists that reliable warning is a property of the network, not the node. A single low-cost accelerometer, however cleverly triggered, will occasionally false-alarm on local noise, and cannot by itself distinguish a nearby small quake from a distant large one. But cheap MEMS sensors, deployed densely and cross-confirmed with accurate timestamps, genuinely contribute — community seismic networks have demonstrated that a crowd of humble sensors can detect and locate earthquakes and shave seconds off warnings for everyone. So the node does two honest things well: it acts immediately and locally (a loud drop-cover-hold alert the instant it triggers, because your own trigger on a real quake is real ground motion under you), and it reports a clean, well-timed detection into a network that does the confirmation and warning. It complements official seismic networks rather than replacing them, and it never pretends a single bench-top box is an authoritative earthquake alarm.
The maths behind it
STA/LTA trigger
On the vibration signal x[n] (e.g. |acceleration| or an axis):
STA = mean of x^2 over a SHORT window (e.g. 1 s)
LTA = mean of x^2 over a LONG window (e.g. 30 s)
ratio = STA / LTA
trigger when ratio > R_on (e.g. 4–8)
de-trigger when ratio < R_off (e.g. 2)
The LTA tracks background; a sudden arrival makes STA jump
while LTA lags → the ratio spikes.
Warning time from wave speeds
For a site at distance D from the epicentre:
t_P = D / v_P, t_S = D / v_S (v_P ~ 6–8, v_S ~ 3–4 km/s)
warning ≈ t_S − t_P − t_detect − t_comms
Detect on the P-wave, alert electronically; the S-wave still
has to travel. Warning grows with D but is zero in the
"blind zone" very near the epicentre.
Networked confirmation and location
A real quake triggers many nodes with consistent timing.
confirmed if ≥ K nodes trigger within a plausible window
epicentre from relative arrival times (t_i) across nodes
(grid-search / triangulation on the array geometry)
magnitude proxy from peak amplitudes vs distance.
One node triggering alone → treated as local noise, not a quake.
Program Flowchart
The firmware is a single cooperative loop. Nothing blocks for long, so networking, sensing and the user interface all stay responsive.
Assembly Instructions
Build on a breadboard first and only commit to solder once the whole system has run for an hour without a fault.
Couple the sensor to the structure
Bolt the accelerometer rigidly to a structural floor slab or wall via a mounting plate, low in the building, so it faithfully moves with the ground.
Keep it away from local vibration sources (HVAC, lifts, foot traffic) that raise the noise floor.
Set up steady sampling and time
Sample the accelerometer at a fixed rate (e.g. 100 Hz) using its data-ready interrupt, and discipline the clock from GPS or NTP so timestamps are accurate to well under a second.
Wire alert, display and network
Connect a loud buzzer/strobe for the local drop-cover-hold alert, an OLED for status/live seismogram, and Wi-Fi for reporting detections to the confirmation server.
Step-by-Step Implementation Guide
Work through these in order. Each step ends in something you can observe, so a failure is always localised to the step you just finished.
Implement the STA/LTA detector
Maintain short- and long-term energy averages of the vibration signal, compute their ratio each sample, and trigger when it crosses R_on, de-triggering below R_off.
cppstalta.ino// Running STA/LTA on the acceleration magnitude (100 Hz). float sta = 0, lta = 0; const float A_STA = 1.0f/100.0f; // ~1 s short window (as an EMA) const float A_LTA = 1.0f/3000.0f; // ~30 s long window const float R_ON = 6.0f, R_OFF = 2.0f; bool triggered = false; // Call once per sample with the (gravity-removed) accel magnitude. bool detect(float accMag) { float e = accMag * accMag; // signal energy sta += A_STA * (e - sta); // fast average // Freeze LTA while triggered so the event doesn't inflate the background. if (!triggered) lta += A_LTA * (e - lta); float ratio = (lta > 1e-9f) ? sta / lta : 0; if (!triggered && ratio > R_ON) { triggered = true; return true; } // onset if ( triggered && ratio < R_OFF) { triggered = false; } // end return false; }sta += A_STA * (e - sta)Implements the short-term average as an exponential moving average of the signal energy, cheap to run every sample and responsive to a sudden arrival.if (!triggered) lta += A_LTAThe long-term background average is frozen while an event is in progress, so the earthquake's own energy does not inflate the baseline and suppress the trigger.if (!triggered && ratio > R_ON)A detection fires when the short-term energy jumps well above the recent background — the STA/LTA signature of a wave arriving.if ( triggered && ratio < R_OFF)Separate on and off thresholds give hysteresis, so the trigger latches through the event and releases cleanly when the shaking subsides.Act locally and report to the network
On a trigger, immediately sound the local alert and send a timestamped detection (with peak amplitude and location) to the confirmation server, which decides if a cluster constitutes a real quake.
Complete Source Code
The listing below is complete and compiles as written — there are no elided sections. Read the annotations under each block before you upload it.
/* ═══════════════════════════════════════════════════════════════
Earthquake Vibration Sensor — ESP32 + accelerometer, STA/LTA
Continuously samples ground motion, detects a P-wave with STA/LTA,
sounds an immediate local drop-cover-hold alert, and reports a
timestamped detection to a network that cross-confirms real quakes.
══════════════════════════════════════════════════════════════════ */
#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <MPU6050.h>
#include <time.h>
#include <math.h>
#define PIN_ALERT 13
#define FS 100 // 100 Hz sampling
MPU6050 accel;
WiFiClient net; PubSubClient mqtt(net);
float sta=0, lta=0, gravity=9.81f;
const float A_STA=1.0f/FS, A_LTA=1.0f/(30*FS);
const float R_ON=6.0f, R_OFF=2.0f;
bool triggered=false;
float peakDuringEvent=0;
uint32_t nextSampleUs=0;
double nowEpochMs() {
struct timeval tv; gettimeofday(&tv,NULL);
return tv.tv_sec*1000.0 + tv.tv_usec/1000.0;
}
void reportDetection(float peak) {
char b[200];
snprintf(b,sizeof b,
"{\"node\":1,\"t_ms\":%.0f,\"peak_g\":%.4f,\"lat\":%.5f,"
"\"lon\":%.5f}", nowEpochMs(), peak/9.81f, NODE_LAT, NODE_LON);
mqtt.publish("quake/detect", b); // network confirms clusters
}
void setup() {
Serial.begin(115200);
pinMode(PIN_ALERT, OUTPUT);
Wire.begin(21,22); Wire.setClock(400000);
accel.initialize();
accel.setFullScaleAccelRange(MPU6050_ACCEL_FS_2); // ±2g, fine resolution
WiFi.begin(WIFI_SSID,WIFI_PASS);
mqtt.setServer(MQTT_HOST,1883);
configTime(0,0,"pool.ntp.org"); // discipline the clock
nextSampleUs = micros();
}
void loop() {
if(!mqtt.connected()&&WiFi.status()==WL_CONNECTED) mqtt.connect("quake-1");
mqtt.loop();
// steady-rate sampling
if ((int32_t)(micros() - nextSampleUs) < 0) return;
nextSampleUs += 1000000UL / FS;
int16_t ax,ay,az;
accel.getAcceleration(&ax,&ay,&az);
float g = 9.81f/16384.0f; // ±2g scale → m/s^2 per LSB
float x=ax*g, y=ay*g, z=az*g;
float mag = sqrtf(x*x+y*y+z*z);
gravity += 0.001f*(mag-gravity); // slow-track gravity
float motion = fabsf(mag - gravity); // ground motion, gravity removed
float e = motion*motion;
sta += A_STA*(e-sta);
if(!triggered) lta += A_LTA*(e-lta);
float ratio = (lta>1e-9f)? sta/lta : 0;
if (triggered && motion > peakDuringEvent) peakDuringEvent = motion;
if (!triggered && ratio > R_ON) {
triggered = true; peakDuringEvent = motion;
digitalWrite(PIN_ALERT, HIGH); // IMMEDIATE local alert
reportDetection(peakDuringEvent); // report onset to network
} else if (triggered && ratio < R_OFF) {
triggered = false;
digitalWrite(PIN_ALERT, LOW);
}
}
Configuration & Calibration
Configuration steps
- Set the sample rate and the STA/LTA window lengths and R_on/R_off thresholds to your accelerometer and site noise.
- Set the node's location for network location/magnitude estimation, and discipline the clock (GPS/NTP).
- Characterise the site noise floor and set the trigger above it.
- Configure the network reporting (MQTT topic/server) and the local alert behaviour.
Calibration procedure
An uncalibrated sensor produces confident, precise, wrong numbers. Do this once per physical unit and record the constants.
Noise floor
Record the STA/LTA ratio over quiet and busy periods; set R_on comfortably above the busiest normal ratio so routine activity does not trigger.
Timing
Verify the clock is disciplined and timestamps are accurate to well under a second by comparing against a reference; multi-node location depends on it.
Response check
Induce a controlled tap/shake and confirm the trigger fires and de-triggers cleanly, and that the local alert activates immediately.
Network Architecture & Connectivity
Communication protocol
Each node reports a timestamped, located detection the instant it triggers — latency is everything in early warning. The server correlates detections into confirmed quakes and issues warnings outward faster than the S-wave travels.
| Topic / endpoint | Direction | Payload |
|---|---|---|
quake/detect | node → server | timestamp, peak amplitude, node location |
quake/confirmed | server → clients | epicentre, magnitude proxy, ETA of shaking |
quake/node/health | node → server | noise floor, clock status, uptime |
Message contract between the device and the broker.
Cloud platform configuration
A confirmation server clusters coincident detections, rejects lone (noise) triggers, estimates epicentre and magnitude from arrival times and amplitudes, and pushes warnings with a shaking-ETA countdown to areas the destructive waves have not yet reached.
Dashboard setup
A live map of node detections and confirmed events, showing the estimated epicentre, the expanding S-wave front, and per-area warning countdowns.
Mobile app integration
On a confirmed event, an immediate warning with the seconds-until-shaking countdown, and triggers for automatic safety actions.
Security considerations
- Authenticate node detections so false quakes cannot be injected to cause panic.
- Prioritise latency and integrity end-to-end — a warning is only useful if it arrives before the shaking.
- Weight nodes by reliability so noisy or spoofed nodes cannot dominate the confirmation.
Testing Procedure & Expected Output
Test from the bottom up. Confirm power, then each sensor in isolation, then the integrated loop — the first failing step tells you exactly where to look.
| Test | What you should see |
|---|---|
| Tap the mounting near the sensor | STA/LTA spikes and triggers; de-triggers as it settles |
| Run a nearby noise source (fan, footsteps) | Ratio stays below R_on if the floor is set correctly |
| Simulate a P-wave-like transient | Immediate local alert; timestamped detection reported |
| Trigger one node only | Network treats it as noise (no cluster) — no wider warning |
| Trigger several nodes coincidently (test harness) | Network confirms a quake and estimates location |
| Check clock discipline | Timestamps accurate enough for cross-node correlation |
Bench-test checklist. If a row fails, stop and fix it before moving on.
Expected output
The node shows a live seismogram and status; the network dashboard shows detections, and on a confirmed cluster, an estimated epicentre, magnitude proxy, and the outgoing warning with countdown to shaking for surrounding areas.
{
"node": 1,
"t_ms": 1785312045678,
"peak_g": 0.031,
"lat": 28.61390,
"lon": 77.20900
}
A single detection like this is only a candidate; when several nodes report coincident, physically-consistent detections, the server confirms an earthquake, locates it from the relative arrival times, and warns areas the S-wave has not yet reached.
Troubleshooting: Common Errors & Fixes
Performance Optimisation
- Sample at a steady rate and keep the STA/LTA update to a few operations per sample so 100 Hz is comfortable.
- Minimise end-to-end latency: detect, alert and report with as little delay as possible — seconds decide the warning's value.
- Discipline the clock continuously; timing accuracy is as important as detection accuracy for the network.
- Freeze the LTA during events and use hysteresis so the detector behaves cleanly without extra computation.
- Replace every
delay()with amillis()comparison — blocking delays are the single most common cause of dropped readings. - Sample sensors on a fixed cadence and publish on a slower one; you almost never need to transmit at the sampling rate.
- Move networking into its own FreeRTOS task so a slow DNS lookup cannot stall the control loop.
- Use
uint8_t/uint16_twhere the range allows; on an 8-bit AVR a 32-bit add costs four times as much. - Batch several samples into one MQTT publish. Radio time, not CPU time, dominates the energy budget.
- Set the MQTT keep-alive to a value that matches your reporting interval so the broker does not churn reconnections.
- For battery builds use deep sleep between samples: an ESP32 drops from ~160 mA awake to about 10 µA asleep, which is the difference between days and months of runtime.
Safety Precautions
- Warning is a network property — never present a single node as an authoritative earthquake alarm.
- This complements, and does not replace, official seismic networks and public warning systems.
- Ensure any automatic safety actions (gas shut-off, lift control) triggered on confirmation are fail-safe and reviewed by qualified engineers.
- Make the local drop-cover-hold alert unmistakable and test it regularly.
- Wear eye protection when soldering or cutting, and solder in a ventilated space — rosin flux fumes are a respiratory irritant.
- Power the circuit through a bench supply with a current limit while you are testing. A 300 mA limit turns a wiring mistake into a beep instead of a dead board.
- Disconnect power before changing any wiring. Hot-plugging a sensor onto a live bus is the fastest way to lose a controller.
Maintenance
- Periodically re-characterise the noise floor as the building's use changes.
- Verify clock discipline and node position accuracy.
- Check the mounting remains rigid and the sensor free of new local vibration sources.
- Test the local alert and the network reporting path regularly.
- Re-check every screw terminal and header after the first week — thermal cycling loosens connections that felt tight on day one.
- Keep the broker and dashboard containers patched, and rotate device credentials at least once a year.
- Recalibrate at the interval given in the calibration section, and keep the constants in a text file next to the firmware — not only in flash.
- Keep a short logbook of firmware versions and what changed. Six months later you will not remember why that constant is 1.083.
Future Improvements & Upgrades
A working v1 is a platform, not a finish line. These are the upgrades that add the most capability for the least rework.
- Upgrade to a low-noise MEMS (ADXL355-class) accelerometer for sensitivity closer to research nodes.
- Add on-device magnitude estimation from P-wave characteristics for faster warnings.
- Contribute to an existing community seismic network protocol for real cross-confirmation.
- Add battery backup so detection survives the power loss an earthquake can cause.
- Design a proper PCB. Once the breadboard version has run for a month, moving to a two-layer board removes the intermittent-contact failures that dominate prototype faults.
- Add over-the-air firmware updates so you never have to physically reach a deployed node again.
- Add persistent local storage (microSD or the on-chip flash) so a network outage does not create a hole in your data.
- Move configuration out of the source: a captive-portal setup page or a JSON config file makes the build reusable without a recompile.
- Add a battery and solar option so the unit survives a power cut and can be sited away from a socket.
- Write a small test harness that feeds synthetic sensor values through the decision logic, so you can validate thresholds without physically triggering the event.
Frequently Asked Questions
References & Learning Resources
These are the primary sources worth reading in full. Manufacturer datasheets always outrank forum posts when the two disagree.
- Earthquake early warning — how it worksReference
- STA/LTA detection algorithm — seismologyReference
- P-waves and S-wavesReference
- Community seismic networks (e.g. MyShake / QCN)Reference
- MEMS accelerometers for seismologyReference