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 8566727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:43:17+00:00 2026-06-11T17:43:17+00:00

Hey Guys I am currently working on a project which will access the accelerometer

  • 0

Hey Guys I am currently working on a project which will access the accelerometer and graph it how ever my code is currently not working and I am unsure of the reasoning, any help will be greatly appreciated.

The program is required to record data for 30 seconds then output a graph how ever it keeps outputting a 0 values for all 3 axis.

The Code:

public class AccelerometerData extends Activity implements SensorEventListener {

public float _x;
public float _y;
public float _z;

boolean senseA = false; 

int Time = 30;
int samplerate=10;
int sampleSize=(Time*1000)/samplerate;
public double[] X = new double[sampleSize];         
public double[] Y = new double[sampleSize];
public double[] Z = new double[sampleSize];

Sensor accelerometer;
SensorManager sm;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    sm=(SensorManager)getSystemService(SENSOR_SERVICE);
    accelerometer=sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sm.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_FASTEST);

    final Timer updateTimer = new Timer();
    updateTimer.scheduleAtFixedRate(new TimerTask(){
        public void run(){
            if (senseA= true){
                for (int i = 0; i < sampleSize; i++){
                    X[i] = _x;                                          
                    Y[i] = _y;
                    Z[i] = _z;                                                  
        }

            }                                                       
        }
    }, 0, samplerate);

  }

public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // TODO Auto-generated method stub

}

public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
        _x = event.values[0];
        _y = event.values[1];
        _z = event.values[2];
        senseA = true;
        }

}

}

The outputted values are as follow:

AccelerometerData data= new AccelerometerData();

double[] dataX =  data.X;   

double[] dataY =  data.Y;

double[] dataZ =  data.Z;

int length = data.sampleSize;

Thank you for your time in advance

  • 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-06-11T17:43:18+00:00Added an answer on June 11, 2026 at 5:43 pm

    Your code for reading from the accelerometer looks fine.

    However, you can’t start the Activity with

    AccelerometerData data= new AccelerometerData();
    

    Instead, you can start the Activity with an Intent, e.g.

    startActivity(new Intent(this, AccelerometerData.class));
    

    Also, the way you store the accelerometer values looks bogus. I assume you want to store the i-th reading at the i-th position in the X,Y,Z arrays. Instead you are overwriting all elements of the arrays with the latest value.

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

Sidebar

Related Questions

Hey guys, Im working with wpf 3d, im currently writing a program that will
Hey guys i am currently working on an android app that will allow me
Hey guys, I currently have a root table view which has a toolbar at
Hey guys I am working on a project where I need to broadcast a
Hey guys, how do you access bookmarks with the sdk? I'm currently making a
Hey guys i have the string: /new/krymson/ currently i have the regex: /\/new\// which
Hey guys Im currently trying to debug some code for a mysqli encapsulation class.
Hey guys... I'm working on creating one of my first websites and currently have
Hey guys I have a query that currently finds the latest comment for each
Hey guys quick question, I currently have an insert statement $query= INSERT into new_mail

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.