How to get user's step count in using accelerometer data?

1.6k views Asked by At

I want to calculate user steps(like pedometer).I know that with iPhone 5s, 6 and 6+ we can use CMStepCounter or CMPedometer class(which use M7 chip of devices) but iPhone 5 and lower versions does not support M7 chip, so we can't use CoreMotion. By searching all over internet i came to know that we can use accelerometer sensor for this purpose. But after spending a lot of time still i'm not able to make an accurate algorithm that works.

Edit2: After spending several days on searching google i tried a lot but still unable to find an working algorithm for counting user step using accelerometer. Can anybody out there who can help me?

1

There are 1 answers

3
eracube On

CMMotionManager is what you are looking for if you are using later versions of iOS. However, if you want to continue with iOS 5 or lower you need to use the following although this is deprecated.

UIAccelerometer * accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.delegate = self;

The method where you can get x, y, z values is:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
    //Check your x,y,z values to find step ... 
}

If you need to know the logic behind step counter you can search and read through in Google :)