IOS aside, there is no easy solution to create an accurate pedometer using only the output of the accelerometer; it's just noisy. Using the gyroscope output (where available) to filter the output will increase accuracy.
But the rough approach here is to the connection code for the pedometer: - the steps are defined as the change in acceleration detected on the Z axis. Assuming that you know the default acceleration (the influence of gravity) here, how you do it:
float g = (x * x + y * y + z * z) / (GRAVITY_VALUE * GRAVITY_VALUE)
Your threshold is g=1 (this is what you will see when standing). Spikes in this meaning are steps. So all you have to do is burst count. Keep in mind that a simple g> 1 will not do, since the g value will increase over a certain period of time by one step and then return (if you build the value over time, it should look like a wave sin, when there is a step - essentially, you want to count the waves of sin)
Keep in mind that this is just something to get you started; You will have to add more complexity to it to increase accuracy. Things like: - hysteresis to avoid false step detection - filtering the output of the accelerometer - determining intervals Here are not included and should be experimented.
source share