Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6194333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:16:44+00:00 2026-05-24T03:16:44+00:00

Would it be possible say, to get the accelerometer to update 50 times a

  • 0

Would it be possible say, to get the accelerometer to update 50 times a second? the reason I want to do this is is that I want to let the accelerometer run, collect all of the different values it records and then return an average.

I initially tried to just collect all of the different values

 yAverage = yAverage + new y; 

and then divide it by a counter that recorded the amount of different recordings.

 counter++;

both lines of code are in the “onSensorChanged” method and will always execute together (as in, if one executes the other will also execute without fail)

However the results I am getting are very inconsistent. if I have the phone lying flat on the table it will calculate almost random different values for the average even though the sensor value never changes and there for should always return the same.

Is there a better way to calculate the average?

I dont know if it matters but I am using floats to store the recorded values and doing the calculations.

Responce to Sherif:
well there isnt really that much code in it, I have 3 float values that get the values from the acclerometer like so:

 y=event.values[1];

and it is located inside the “onSensorChanged” method inside the SensorEventListener.

I suppose the pseudo code would go like this:

 float yAverage = 0

 onSensorChanged{
    float y = event.values[1];
    if (y < 0){
       y = y * -1;
    }
    yAverage = yAverage + y;
    counter++;
 }

and then in another method it calculates;

 yAverage = yAverage / counter;

It then get’s printed to the screen

it’s not a complicated method but I just can’t figure out why it is so inaccurate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:16:44+00:00Added an answer on May 24, 2026 at 3:16 am

    I have no idea if it is an execution error but I think it is a logical error

    SensorManager mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
    Sensor mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    public void onSensorChanged(SensorEvent event) {
        float y = event.values[1];
        if (y < 0){
            y = y * -1;
        }
    yAverage = yAverage + y;
    counter++; 
    }
    

    Summary:

    • make sure yAverage is global

    • make sure you’re using TYPE_ACCELEROMETER

    • Don’t forget that when put on a table you will get high values for value[1] due to gravity and Normal

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to do so? Let's say I want to get the last
I'm not sure if this is possible, but if I wanted to say get
Would it be possible to write a class that is virtually indistinguishable from an
Would it be possible to add a new operator to the String class that
Would it be possible to write a script that gave the user the ability
Let's say I have this object: [JsonObject] public class User { [JsonProperty(PropertyName = id)]
Let's say I have a query result that looks as follows: ID NAME Phone
I want to get the number of Registrations back from a time period (say
If possible I would like to get some ideas to get the following done
Given a function, is it possible to get its name? Say: func foo() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.