1. Introduction
In this final evolution of our safety series, we are building a "Global Alert" station. This system detects Earthquakes using an accelerometer, Tsunamis via rapid sea-level shifts, and continues to monitor Floods and Fire. With SD Card logging and ThingSpeak Cloud, this is a professional-grade project for any electronics enthusiast.
2. Components
Microcontroller: NodeMCU ESP8266.
Earthquake Sensor: MPU6050 (3-Axis Accelerometer).
Tsunami/Flood Sensor: HC-SR04 Ultrasonic Sensor (placed over water).
Fire Sensor: MQ-2 Smoke/Gas Sensor.
Data Storage: Micro SD Card Module + SD Card (FAT32).
Alert System: I2C LCD 16x2 and a High-Decibel 5V Buzzer.
Cloud: ThingSpeak IoT Platform.
3. Circuit and Connections
| Pinout Diagram NodeMCU |
| MPU6050 Pinout Diagram |
| Pinout Diagram of MQ-2 Sensor |
| Pinout Diagram of Buzzer |
| Component | Pin on Sensor | Pin on NodeMCU |
| MPU6050 (I2C) | SDA / SCL | D2 / D1 |
| I2C LCD | SDA / SCL | D2 / D1 (Shared) |
| SD Card (SPI) | CS / MOSI / MISO / CLK | D8 / D7 / D6 / D5 |
| JSN SR04T | Trig / Echo | D3 / D4 |
| MQ-2 Sensor | Analog Out | A0 |
| Buzzer | Positive (+) | RX (GPIO3) |
4. Detailed Step-By-Step Circuit Working
Seismic Detection: The MPU6050 constantly tracks gravity on the X, Y, and Z axes. A sudden spike in these values indicates a tremor or earthquake.
Tsunami Logic: While a flood is a slow rise, a Tsunami is a massive, high-speed surge. The HC-SR04 detects if the water level changes by more than 20cm in less than 2 seconds.
Redundant Logging: The data is written to the SD Card every 5 seconds. If the earthquake knocks out the Wi-Fi, the history of the event is saved locally.
Cloud Reporting: ThingSpeak receives the "Vibration Level" and "Water Depth" to create a live disaster map.
5. Libraries to be Included
Adafruit_MPU6050.h(For earthquake sensing)Adafruit_Sensor.h(Unified sensor driver)ThingSpeak.hSD.h&SPI.hLiquidCrystal_I2C.h
6. Code
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>
#include <SD.h>
Adafruit_MPU6050 mpu;
LiquidCrystal_I2C lcd(0x27, 16, 2);
WiFiClient client;
const int trig = D3; const int echo = D4;
const int buzzer = 3; // RX Pin
unsigned long myChannel = 1234567;
const char* myKey = "API_KEY_HERE";
void setup() {
lcd.init(); lcd.backlight();
mpu.begin();
pinMode(trig, OUTPUT); pinMode(echo, INPUT);
pinMode(buzzer, OUTPUT);
WiFi.begin("SSID", "PASS");
ThingSpeak.begin(client);
SD.begin(D8);
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
digitalWrite(trig, LOW); delayMicroseconds(2);
digitalWrite(trig, HIGH); delayMicroseconds(10);
digitalWrite(trig, LOW);
float dist = pulseIn(echo, HIGH) * 0.034 / 2;
// Earthquake Detection (Threshold > 15m/s^2)
bool earthquake = (abs(a.acceleration.x) > 15 || abs(a.acceleration.y) > 15);
// Tsunami Detection (Rapid water rise)
bool tsunami = (dist < 10);
if (earthquake || tsunami) {
digitalWrite(buzzer, HIGH);
lcd.clear(); lcd.print("QUAKE/TSUNAMI!");
ThingSpeak.setField(1, 1); // Alert Status
} else {
digitalWrite(buzzer, LOW);
lcd.setCursor(0,0); lcd.print("Stable Ground");
}
ThingSpeak.setField(2, a.acceleration.x);
ThingSpeak.setField(3, dist);
ThingSpeak.writeFields(myChannel, myKey);
delay(15000);
}
7. Detailed Step-By-Step Code Working
abs(a.acceleration.x): We use absolute values because an earthquake can shake the sensor in both positive and negative directions.
Tsunami Trigger: The code checks if the distance between the sensor and the water is critically low. In a real-world scenario, you would compare the current reading to a "rolling average" to detect a sudden surge.
Field Mapping: Field 1 acts as a "Digital Switch" (0 for safe, 1 for alert) so you can set up email notifications on ThingSpeak.
8. Tips
Mounting: The MPU6050 must be bolted to a solid surface (like a wall or heavy base). If it is loose on a breadboard, you will get "false earthquake" alarms.
I2C Conflict: Ensure your LCD and MPU6050 have different I2C addresses (usually 0x27 and 0x68).
Power: Use a high-quality 5V power supply; SD cards and Wi-Fi modules can draw up to 500mA during write cycles.
9. Uses
Coastal Safety: Monitoring tide levels for sudden Tsunami threats.
Structural Health: Placing sensors on bridges or buildings to detect vibration fatigue.
IoT Networking: Connecting multiple stations to a central ThingSpeak dashboard for a "Regional Alert" system.
10. Conclusion
This project represents the peak of beginner IoT electronics. By integrating seismic, aquatic, and atmospheric sensors into a single cloud-connected device, you have created a system that mirrors the technology used by global disaster response teams.