Earthquake Sensor

If you want to try, the changes are uploaded on github; or you can wait for the results of the WiFi discconnect problem.

Looks ok.

NEW CHANGES AND UPDATES:

  • Sending commands ā€˜RESETā€™, ā€˜UPDATEā€™ and ā€˜CHANGE_PGAā€™ deprecated. They will be under ā€œm5seismo/commandā€ topic as explained below.
  • Event message is published every XX seconds now (default 30 secs)
  • Removed AHRS code since we only use accel data.
  • Increased MQTT pga value decimals from 2 to 4.
  • Added ā€œm5seismo/commandā€ topic. One can send commands only to this topic now, in Json format:

Commands Topic: ā€œm5seismo/commandā€

Should 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 like:

{
    "lcd_brightness" : 10
    "update_period" : 9
}

"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.

Hello. I have updated to the latest code. Trying to change the pga_trigger, but it is not taking the changes. I can see the state change to changed_pga_trigger, but the pga_trigger remains unchanged.

service: mqtt.publish
data:
  topic: house/seismom5/command
  payload: "{ \"pga_trigger\": 0.020 }"

Yeah, it was changing in the background but not sending a related pga_trigger message. Corrected it now. You can try it.

after a few days this is whatā€™s happening. faulty sensor??

Try a reset, it recalibrates the accelerometer.

yea, I have. Sometimes it recalibrates by itself. I mean a reset will work but after a few days, it jumps back to this. I will try a reset again.

A new version:

  • Includes a web page where you can see and change parameters.
  • WebSerial from the web page
  • Wifi, MQTT and other details are entered from the ā€œconfig.hā€ file now, before compilation.

Planning to add STA/LTA method for earthquake detection laterā€¦

My M5stick Plus is still acting up at random. Have tried several resets, reinstall code. It would be stable for a day or so. I noticed the 6-Axis IMU used for both versions are different models.

M5StickC: 6-Axis IMU SH200Q
M5StickC Plus: 6-Axis IMU MPU6886

M5StickC earlier versions used SH200 but all later versions used MPU6886, mine is also MPU6886.

There seems a problem with the calibration; sometimes the noise is lower than 0.003, sometimes it goes up to 0.015. Sometimes when i reboot the M5 it goes on a week without any noise problem, but sometimes it starts with a high noise. So when that happens, i make sure to reset and recalibrate it 3-4 times in order to keep the noise under 0.003. I am looking into this problem, i never had this problem with MPU6250.

There are some things to consider also, normally accelerometers are open to interference noise, because of temperature or electromagnetic waves. My code does not include anything to overcome temperature, it looks minimal for accelerometer and we are not using the gyro.

But your installation seems sketchy to me, you said you installed it on top of a faceplate. Is there AC electricity under that faceplate? That might create interference i believe, so is it possible to test it somewhere where there are minimum electricity interference? Because mine also is installed near a TV set and i am having some minimal problems with it, but the second test stick i use on a table works perfectly good. So i am planning to move the first stick a little away from the TV set.

I am also having tests with M5AtomLite, ADXL345 and MPU6250. Will post the outcome soon.

The faceplate I have placed the sensor over it is a single plug outlet. The only power use is from the sensor itself and an esp8266 I use for a pir sensor. The reason I place over a faceplate because my wall is not smooth. I think the double side tape will falll off after awhile.

So as a test, maybe I will place it over a table that seldom use.

This is brilliant, thank you! This is my first reply on this site, forgive me if I am muddying the water.

Is there a step-by-step tutorial for this? I have ordered the parts and will be scouring this thread to figure it out but I am a definite novice.

I run a small international preschool in Japan and would love to put this on one of our support beams and have it set off an alarm, shut off the gas, and open the doors for us in the event of a strong quake to free up the teachers a little in an emergency. Do you think it will be reliable enough? We are also on a main road so I am hoping to be able to set the threshold after having it connected for around a week to find the background levels.

Great work and this little device is amazing!

EDIT: Also, I forgot to add; is it possible to make 2 or 3 of these and trigger the alarm if all the devices go over the threshold to reduce interference problems? I think I can do that with conditions in HA but I wonder if there is a better way?

is it possible to make 2 or 3 of these and trigger the alarm if all the devices go over the threshold to reduce interference problems?

Iā€™ve never thought about that. Though it would be an overkill. Hoping the OP has made some progress in isolating the calibration fluctuation issue.

Hey @DaleJP, i can help you with the steps from DM once you get the parts.

In the meantime, I have found a bug on offset setting, so after correcting it it is a lot more stable and less noise.

I canā€™t definitely recommend it to be reliable on earthquakes, because i am neither a seismologist-scientist, nor this is a professional attempt. Especially when there is preschool kids involved, i wouldnā€™t count my life on it.

Actually, i also thought about using 2 of these to create a structural vibration measuring device, to compare each others values and trigger when both of them are triggered. That will be the next step.

I also am now testing the STA/LTA (Short Term/Long Term Average) method, which is being used in seismic data analysis. That will compare the 1sec average and 30 sec average values and if that 1 sec average is higher than anticipated, it will trigger the alarm.

I am going to upload the corrected calibration and other properties on github hopefully next week.

This is the 7 days pga and 6 hrs x,y,z graphs on Grafana. Please note that the spikes on pga graph are all tests, not really earthquakesā€¦


And here is this graph, starting from 00:00 the noise from the corrected calibration version.

1 Like

Brilliant, thank you.

We will obviously continue our current procedure in an earthquake but with an audible confirmation that this automatic system has kicked in based on sensors at the gas valve and doors. If they hear the confirmation, they need not leave the children and it acts as a fallback if the teachers physically cannot leave the children or access the gas and doors or we are out for a walk etc.

The parts should be arriving today. I could only get the plus variant within a reasonable time frame.

I flashed my first esphome device yesterday so I am very new to this. Iā€™m more of a copy/paste programmer than someone who actually understands what they are doing. You have to love the internet for enabling that!:sweat_smile:

@duceduc I donā€™t think a fallback is overkill, really. It is common in basically everything else I do. It would be nice to save money and to have a single device be sufficient but even nicer to have a backup. I wouldnā€™t like to take away the motivation to improve the code, thoughšŸ˜‰.

The nicest thing about this device will be to have confirmation at those weird moments when you are all looking at each other saying ā€œDid you feel that?ā€ before you step into gear. The data will be interesting, too.

Iā€™d like to make these for different school owners and people I know and have them send their data to my server to see the data from different areas after a quake.

Thanks again and Iā€™ll let you know when the parts arrive.

The nicest thing about this device will be to have confirmation at those weird moments when you are all looking at each other saying ā€œDid you feel that?ā€ before you step into gear. The data will be interesting, too.

Actually that was my starting point. I have some chronic diseases which leads to false feelings like the ground is shaking; and i can never make sure if it is just me shaking or is it really an earthquake. Yes, the earthquakes happen so often in my city which is in Turkiyeā€¦

Oh btw, on March, a Phd Professor on Earthquake Resistant Structures will visit my workplace for an EU sponsored project and will install professional grade seismic structural accelerometer in the building (That is not related in any way to my project). I am planning to share my project with him so that he might guide me in the right path scientifically.

1 Like

I absolutely understand. After the big earthquake in 2011, we had aftershocks for months and it felt like we were always swaying. I sometimes have dizzy spells too and think that it might be a quake.
I have a fish tank in my office that is my own personal quake-checker but it will be useful to have it elsewhere.

That is exciting about the Professorā€™s visit. I look forward to any fruits of it we might enjoy as a resultšŸ˜…

I have it up and running now.

Thank you for your help and your great work!

Corrected calibration version is uploaded into draft branch of seismoM5 github page, and it is for testing purposes. Sorry for the mess of the code, i will try to tidy it up a bit when i find some time.

CHANGES:

  • Fixed the bug on offsets, so more stable calibration and readings.
  • Changed default mqtt topic to ā€œseismoM5ā€ instead of the old ā€œm5seismoā€
  • Calibrate command (MQTT or web) it just recalibrates without a disconnect or ESP32 reset
  • Added a STA/LTA checkbox on web page, which uses STA/LTA method for earthquake triggers, instead of PGA threshold trigger. If you enable this, PGA trigger is not used.
  • OTA firmware upload is handled from platformio now:

The first upload should be a Serial connection upload. After that, these 2 lines can be uncommented (delete ā€œ;ā€ characters) from platformio.ini file for OTA firmware uploading.

;upload_port = seismoM5.local
;upload_protocol = espota

If you like you can use this code from draft branch to test.

Btw, you can use 2 of these sticks for backup and compare with the way it is nowā€¦ Just change these on config.h file for the 2nd stick:

#define WIFI_HOSTNAME "seismoM5"

#define MQTT_PUB_TOPIC_MAIN "m5seismo"

to:

#define WIFI_HOSTNAME "seismoMb"

#define MQTT_PUB_TOPIC_MAIN "m5seismb"

So now you have 2 devices on 2 different mqtt topics, m5seismo and m5seismb. You can compare the /state of these 2 on HA and if they both send ā€œEARTHQUAKEā€ on /state that means they are both in vibration. This is just for trying, i will add master-slave type configuration code for more than one stick installations.

1 Like

Iā€™ve flashed the new code and tested the OTA. Everything seems to be working well and I can access the web UI. What is STA/LTA method?

Everything seems fine except it is showing as unavailable in HA. Should I change the config yaml?

EDIT: I renamed the topics from ā€œM5seismoā€ to ā€œseismoM5ā€ and they are all showing up.

EDIT 2: The STA/LTA algorithm continuously keeps track of the always-present changes in the seismic noise amplitude at the station site and automatically adjusts the seismic stationā€™s sensitivity to the actual seismic noise level. As a result, a significantly higher sensitivity of the system during seismically quiet periods is achieved and an excessive number of falsely triggered records is prevented, or at least mitigated, during seismically noisy periods. Calculations are repeatedly performed in real time. This process is usually taking place independently in all seismic channels of a seismic recorder or of a seismic network.

https://gfzpublic.gfz-potsdam.de/rest/items/item_4097/component/file_4098/content

Yes, that is the holy article of STA/LTA :slight_smile: It is much more sensitive compared to PGA Trigger.

For now, it is being measured on PGA value, i did not do it for x,y,z independently, since PGA is the vectoral sum of x,y and z anyways.

Very basically, LTA is the long term average of X seconds of PGA values. STA is the short term average of Y seconds of PGA vaues. The code compares STA with LTA and if it exceeds some certain scale, it triggers the earthquake signal. The purpose is to eliminate noise effects and fake trigggers. Again, very basically this method is like it changes the PGA Trigger value real time, according to the noiseā€¦

As you can see from that article, parameters are very important. The parameters are like this:

  1. In stalta.h file:
const int sta_lta_element_count = 10; // Reads per second
const int STA_WINDOW_SIZE = 5; // 0.5 secs
const int LTA_WINDOW_SIZE = sta_lta_element_count * 30; // secs
const int PEM_WINDOW_SIZE = 8;

sta_element_count: 10 reads per second from the MPU, donā€™t change this!

STA_WINDOW_SIZE: Short term average of 5 reads is taken as PGA. Actually that means the earthquake trigger will fire 0.5 secs later than the first shake begins. Thatā€™s the downside of this method.

LTA_WINDOW_SIZE: Long term average of 30 seconds PGA vaue is taken as regular noise level.

PEM_WINDOW_SIZE: Not being used yet.

  1. In config.h file:
//STA/LTA
#define trigger_threshold 2.5
#define detrigger_threshold 1.4

trigger_threshold: If STA is larger than 2.5 times of LTA value, this will trigger earthquake alert.

detriggfer_threshold: The fired earthquake alert will continue until the STA is smaller than 1.4 times of LTA, if it is lower than it will end the earthquake alert.

We have to change and adjust these parameters according to our location, noise levels etc. It is still in test phase so i really donā€™t know how much reliable it is.