title: Detect if the Person falls down
body: <p>I am creating an app in android where i need to detect if the person has fall down. I know that this question has been asked and answered as to use vector mathematics in other forums but i am not getting the accurate results out of it.</p>
  
  <p>Below is my code to detect the fall:</p>
  
  <pre><code>@Override
  public void onSensorChanged(SensorEvent arg0) {
    // TODO Auto-generated method stub
    if (arg0.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
      double gvt=SensorManager.STANDARD_GRAVITY;
  
      float vals[] = arg0.values;
      //int sensor=arg0.sensor.getType();
      double xx=arg0.values[0];
      double yy=arg0.values[1];
      double zz=arg0.values[2];
      double aaa=Math.round(Math.sqrt(Math.pow(xx, 2)
                                      +Math.pow(yy, 2)
                                      +Math.pow(zz, 2)));
  
      if (aaa&lt;=6.0) {
        min=true;
        //mintime=System.currentTimeMillis();
      }
  
      if (min==true) {
        i++;
        if(aaa&gt;=13.5) {
          max=true;
        }
      }
  
      if (min==true &amp;&amp; max==true) {
        Toast.makeText(FallDetectionActivity.this,"FALL DETECTED!!!!!" ,Toast.LENGTH_LONG).show();
        i=0;
        min=false;
        max=false;
      }
  
      if (i&gt;4) {
        i=0;
        min=false;
        max=false;
      }
    }
  }
  </code></pre>
  
  <p>To explain the above code i have used the vector sum and checking if the value has reached below or equal to 6(while fall) and suddenly greater than 13.5(while landing) to confirm the fall.</p>
  
  <p>Now i was been told in the forums that if the device is still the vector sum will return the value of 9.8. While fall it should be close to 0 and should go to around 20 while landing. This doesn't seem to happen in my case. Please can anybody suggest if i am going wrong anywhere?</p>