- Home /
iPhone accelerometer values are not consistent
Hello guys, i am working on a bike game. i have a problem like if i put my iphone on a table in a static position still i can see its values are changing. its values are not consistent. can anybody tell me why is that so?
i,ll be very thankful.
Answer by Dreamblur · May 28, 2011 at 07:19 PM
The accelerometer reads all acceleration in units of g (earth's gravitational acceleration on relatively small object near its surface = -9.81 m/s). What that means is that it will read normal gravitational acceleration as 1.0 and any acceleration with a lesser or higher magnitude accordingly. Since all forms of gravity are constant (i.e., we don't float above the ground), that means the accelerometer will always read a downward acceleration even when the device is at rest. However, since the earth itself is moving and prolly from the accelerometer's method of measurement, the values received from that reading are not constant and will always change by a very small fraction. Regardless, the downward acceleration read when the device is at rest will always be very close to 1.0g. Also, since the earth is not completely flat, there is a very small angle of incline on the earth's surface which results in some gravitational acceleration also leaking to the x- and z- axes.
You should also take in account that every practical sensor suffers from electrical noise and drift, so the values read will always show some inaccuracies. Define a limit - say, 0.05g - and only do anything when the changes are bigger than that. If you have to show the readings in a bar or display, you can do some sort of filtering. The moving media is easy to implement: keep the last 30 to 50 readings in a fixed size float array, and show its mean value (sum/array size). Each time you get a new reading, shift everybody one position towards the end of the array and store the new value in the first position.
Adding to aldonaletto's comment, the datastructure should probably be a System.Collections.Generic.Queue, since it obeys the FIFO-behavior described there.
Answer by Graham-Dunnett · May 28, 2011 at 06:34 PM
I don't think you should expect the numbers to be constant, even when the phone is not moving at all. How much variation are you seeing?
Answer by dilmer · Sep 12, 2013 at 06:59 AM
Check out this control I wrote which may help you out.
Guys,
I worked in a game recently which needed an accelerometer control for a spaceship I created which is now available in the App Store as well, during my programming I found myself using this control for other games. I would recommended as is super easy to integrate into your game.
Download Now from the Asset Store
Your answer

Follow this Question
Related Questions
Bag Toss Unity Accelerometer 1 Answer
A node in a childnode? 1 Answer
Unity iPhone - Camera Orthographic size - Differing results 1 Answer
iTween(JS version) could not be used in Unity iPhone? 3 Answers
Unity Penelope Tutorial and iPhone 0 Answers