<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Need help arduino earthquake detector - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/need-help-arduino-earthquake-detector/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Wed, 22 Apr 2026 20:39:46 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Need help arduino earthquake detector</title>
                        <link>https://www.tweaking4all.com/forum/arduino/need-help-arduino-earthquake-detector/#post-4280</link>
                        <pubDate>Sun, 10 Jul 2022 11:13:35 +0000</pubDate>
                        <description><![CDATA[p.s. maybe this article is helpful for your project?
Is this the project you got your code?]]></description>
                        <content:encoded><![CDATA[<p>p.s. maybe <a href="https://www.eeweb.com/earthquake-detector-with-accelerometer/" target="_blank" rel="noopener">this article</a> is helpful for your project?</p>
<p>Is <a href="https://how2electronics.com/arduino-earthquake-detector-accelerometer/#Arduino_Source_CodeProgram" target="_blank" rel="noopener">this the project</a> you got your code? </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/need-help-arduino-earthquake-detector/#post-4280</guid>
                    </item>
				                    <item>
                        <title>RE: Need help arduino earthquake detector</title>
                        <link>https://www.tweaking4all.com/forum/arduino/need-help-arduino-earthquake-detector/#post-4279</link>
                        <pubDate>Sun, 10 Jul 2022 11:08:27 +0000</pubDate>
                        <description><![CDATA[Hi vjcp,
I do not have an accelerometer available (or earthquakes for that matter 😋  ).
This is an interesting challenge for sure though.One key problem would be this:
Say we detection mo...]]></description>
                        <content:encoded><![CDATA[<p>Hi vjcp,</p>
<p>I do not have an <span>accelerometer available (or earthquakes for that matter 😋  ).</span></p>
<p>This is an interesting challenge for sure though.<br />One key problem would be this:</p>
<p>Say we detection motion at 0 seconds. And again at 1 second, 2 seconds, 4 seconds, and ... 6 seconds.<br />This could be seen as an earthquake detection, right? But when we strictly stick to 5 seconds it would not be seen as such.</p>
<p>Maybe we'd need to define clearer what is considered motion that indicates an earth quake.<br />For example:</p>
<p>X number of motion detection within 5 seconds? <br />Or at the most X seconds between two motion detections?<br /><br /><br /></p>
<p> </p>
<p>Note: I'd make a separate function for motion detection to make code more readable. Something like this (returns true or false):</p>
<pre contenteditable="false">bool motionDetected()
{
  int value1 = analogRead(x); // reading x out
  int value2 = analogRead(y); // reading y out
  int value3 = analogRead(z); // reading z out

  int xValue = xsample - value1;  // finding change in x
  int yValue = ysample - value2;  // finding change in y
  int zValue = zsample - value3;  // finding change in z

  return (xValue &lt; minVal || xValue &gt; maxVal  || yValue &lt; minVal || yValue &gt; maxVal  || zValue &lt; minVal || zValue &gt; maxVal);
}</pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/need-help-arduino-earthquake-detector/#post-4279</guid>
                    </item>
				                    <item>
                        <title>Need help arduino earthquake detector</title>
                        <link>https://www.tweaking4all.com/forum/arduino/need-help-arduino-earthquake-detector/#post-4275</link>
                        <pubDate>Sat, 09 Jul 2022 06:44:49 +0000</pubDate>
                        <description><![CDATA[hello guys, i am doing this project to detect earthquake, when there is still movement after 5 seconds the arduino will activate the relay. My problem is the timer resets immediately when th...]]></description>
                        <content:encoded><![CDATA[<p>hello guys, i am doing this project to detect earthquake, when there is still movement after 5 seconds the arduino will activate the relay. My problem is the timer resets immediately when the sensor goes back to its original position so the 5 second timer does not end and it keeps resetting.</p>
<p>i used adxl 335 accelerometer sensor</p>
<p>here is my code:</p>
<pre contenteditable="false">#define buzzer 12 // buzzer pin
#define led 13  //led pin
#define relay 11 // relay pin

#define x A0  // x_out pin of Accelerometer
#define y A1  // y_out pin of Accelerometer
#define z A2  // z_out pin of Accelerometer

/*variables*/

int xsample = 0;
int ysample = 0;
int zsample = 0;
long start;


unsigned long movementStarted;
unsigned long currentMillis;
unsigned long period = 5000;
/*Macros*/

#define samples 50
#define maxVal 4   // max change limit
#define minVal -4    // min change limit
bool moving = false;

void setup()
{
  pinMode(buzzer, OUTPUT);
  pinMode(led,    OUTPUT);
  pinMode(relay,  OUTPUT);

  for (int i = 0; i &lt; samples; i++) // taking samples for calibration
  {
    xsample += analogRead(x);
    ysample += analogRead(y);
    zsample += analogRead(z);
  }

  xsample /= samples; // taking avg for x
  ysample /= samples; // taking avg for y
  zsample /= samples; // taking avg for z
  delay (3000);
}
void loop()
{
  currentMillis = millis();

  int value1 = analogRead(x); // reading x out
  int value2 = analogRead(y); // reading y out
  int value3 = analogRead(z); // reading z out

  int xValue = xsample - value1;  // finding change in x
  int yValue = ysample - value2;  // finding change in y
  int zValue = zsample - value3;  // finding change in z


  // Check if there is currently movement.
  if (xValue &lt; minVal || xValue &gt; maxVal  || yValue &lt; minVal || yValue &gt; maxVal  || zValue &lt; minVal || zValue &gt; maxVal)
  {
    if (moving == false)                          // Did we just started moving?
    {
      movementStarted = currentMillis;            // Capture the time we started moving
      tone(buzzer, 1000);
    }
    moving = true;                                // Flag that we are moving 
    if (currentMillis - movementStarted &gt; period) // Check how long we have been moving for 
    {
      digitalWrite(relay, HIGH);                   
    }
  }
  else                                          // Not moving.
  {
    moving = false;                               // Flag that we are not moving
    noTone(buzzer); 
                                    // Turn relay OFF (active LOW)
  }
}</pre>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/need-help-arduino-earthquake-detector/#post-4275</guid>
                    </item>
							        </channel>
        </rss>
		