Updates on the project and details are in this page...
Living in a highly seismic activity city brings its own challenges. Waking up in the middle of the night with a shake and wondering the epicenter and magnitude of the earthquake, praying that everyone you love is safe etc. You start browsing through each of the Seismology networks to get a little bit more knowledge about it but you have to wait at least some minutes to get some reliable information about this specific earthquake.
Having a smart home with lights, rolling shutters, lots of sensors, actuators etc., an earthquake sensor was the missing piece. If only there was an affordable sensor which will activate during an earthquake and gives audio and visual warning, shut off gas valves, open some doors, rolling shutters and lights for a safe escape route. A professional or amateur grade seismograph or structural vibration sensors were out of question for me since I am nowhere near being a seismologist or do I have the time to analyze the output of these sensors. So I came up with an amateur idea of using M5StickC in use.
** Please be aware that this is an amateur attempt at best and do not rely solely on this sensor for your life. It may or may not work as intended.SeismoM5 is an Earthquake Sensor Implementation on M5StickC, using its own MPU6886 accelerometer. Although MPU6886 in M5StickC is a bit on the noisy side; disabling Gyro and using an accel calibration helped a little. The properties of this project is:
- Calibrate MPU6886 accelerometer and use calibration results as offsets.
- Use DLPF - 5 Hz.
- Use MQTT and send data, only when an earthquake happens.
- Draw X, Y, Z accel results on M5stickC screen as graph, only when an earthquake happens.
- Show PGA always.
- Emergency alerts; Red Led and SPK HAT sound warning during an earthquake.
I am nowhere near being a Seismologist or I understand anything about. It is just that I live in an overly active Seismic zone. The idea came up for adding an earthquake sensor to the smart home; to shut gas valves off and open some rolling shutters for an escape route during an earthquake.
So I tried some signal algorithms to get the most effective earthquake trigger mechanism possible. Among these, STA/LTA method was very close to get rid of the noise and unwanted man made noises and peaks. However, the test results were not succesfull for me. So I opted out for a simple PGA calculation:
pga = sqrt(x_vector_mag * x_vector_mag + y_vector_mag * y_vector_mag + z_vector_mag * z_vector_mag)*scale_factor;
The triggering mechanism is, if PGA exceeds limit, that is an earthquake. PGA gives intensity too, but I do not know how reliable that is.
UsageThis is a Platformio code. First of all, the user needs to fill WiFi and MQTT server details in main.cpp. Other parameters like Seismic, MPU calibration or screen properties can be changed for best fit after some tests and trials.
Button A of M5stickC toggles MQTT server connection. If bottom right corner of the screen shows MQTT, the server is connected.
Button B of M5stickC resets M5StickC for recalibration purposes
"online" or "offline"
State: m5seismo/stateINIT_MPU: Init MPU6886.
WAIT: Wait for 10 seconds, to get ready to keep M5StickC steady.
CALIBRATION: MPU6886 Accelerator find offsets and send to MPU registers for calibration. Might take up to 1 minute.
LISTENING: Everything is ready and listening for earthquakes.
EARTHQUAKE: Earthquake is happening
Events: m5seismo/event{"x":"-85", "y":"-1097", "z":"16305", "pga":"0.07"} Sample
Momentary x, y, z parameters and PGA in (g). Only send while an earthquake occurs.
PGA results can be compared with the values in:
PGA Correlation with the Mercalli scale
or
Japan Meteorological Agency seismic intensity scale
Commands: m5seismo/commandShould be send in JSON format as follows:
{
"pga_trigger": 0.0150,
"update": false,
"reset": false,
"speaker_enable" : true,
"lcd_brightness" : 7,
"continuous_graph" : false,
"update_period" : 30
}
There is no need to send this full message, any item can be send standalone or together with any other item.
"pga_trigger" : float - Changes the PGA Trigger. If the PGA Trigger is ever changed, SeismoM5 saves this value permanently and use it from then on even after you reset SeismoM5.
"reset" : bool - If true, resets M5StickC for recalibration purposes.
"update" : bool - If true, sends a one time event message update request.
"speaker_enable" : bool - If true, enables the SPK HAT Speaker, false disables it.
"lcd_brightness" : int - Sets the standby LCD brightness, should be between 7-15, 15 being the brightest.
"continuous_graph" : bool - If true, draws the graph continuously, even when there is no earthquake.
"update period" : int - Sets the update period of event mqtt message to be send, even there is no earthquake, in seconds.
SeismoM5 Web PageYou can connect to SeismoM5 with its IP address to monitor or change:
- Change PGA Trigger Value
- Change standby LCD Brightness
- Change the update period of event mqtt message to be send, even there is no earthquake, in seconds
- Use STA/LTA Method for triggering, this disables PGA Triggering.
- Enable/Disable Speaker
- Enable/Disable continuous graph
- Change Logging Type (Serial, WebSerial, Both or None)
- WebSerial Output
- Recalibrate MPU
- Restart SeismoM5 ESP32
Seismologists mount accelerometer based seismic sensors to the lowest point of the structure, close to the ground as possible. However, since this is an amateur earthquake sensor, I mount it as high as possible in the house, on a wall. You can use the in-built magnets of M5StickC to attach it to a metal surface but as I experienced they are not so strong and may fall off during an earthquake. Double sided adhesive mounting tapes can also work, but make sure the wall paint is a stickable one. All in all, it should be mounted very firm and be careful about the x, y, z axis of the accelerometer; use a carpenters level if required.
** Due to the screen position, x axis is used as z axis and z axis is used as x axis within the code.
Comments