An accelerometer in mobile devices is a MEMS sensor that measures linear acceleration along three axes to determine device orientation and movement. According to the Google Android Sensors Guide (2025), the accelerometer is the most widely used sensor in mobile applications. MEMS technology allows the sensor to be placed in a 1 mm chip consuming less than 1 mW of power.
Key Takeaways
An accelerometer is a microelectromechanical (MEMS) sensor that measures the projection of acceleration onto three mutually perpendicular axes: X (horizontal, pointing right), Y (vertical, pointing up), and Z (perpendicular to the screen plane). At rest, the accelerometer shows 9.8 m/s² on the Z axis — this is the acceleration due to gravity directed toward the Earth’s center. Based on this value, the system determines device orientation: if the Z value is close to 0 and the Y value is close to -9.8 m/s², the device is rotated horizontally. The accelerometer measurement range is typically ±2g, ±4g, ±8g, or ±16g depending on the chip model.
Modern accelerometers are characterized by several key parameters: sensitivity (from 0.001 m/s²), sampling rate (up to 1000 Hz), measurement range, and noise level. Flagship devices use STMicroelectronics LSM6DSO or Bosch BMI270 sensors with a frequency of up to 1600 Hz and power consumption of less than 0.5 mW in active mode. The higher the sampling rate, the more detailed the signal the application receives — games require 200–400 Hz, while step counting needs only 10–50 Hz. Sensor noise affects measurement accuracy and is usually compensated by a low-pass filter at the OS level.
A MEMS accelerometer internally consists of a microscopic silicon structure: a proof mass suspended on elastic cantilevers between fixed electrodes. When acceleration occurs, the mass shifts, changing the capacitance between the moving and fixed elements — this change is measured and converted into an electrical signal. A closed-loop feedback circuit holds the mass in the center position using electrostatic force, ensuring linearity across the entire range. In open-loop systems, the mass moves freely, making calculations simpler but accuracy lower. According to STMicroelectronics (2025), closed-loop accelerometers achieve accuracy of up to 0.001g with a temperature drift of less than 0.1 mg/°C.
The three axes of the accelerometer correspond to three spatial dimensions: X (left-right tilt), Y (up-down), and Z (forward-backward relative to the screen). When the device lies on a table with the screen facing up, the gravitational acceleration vector points along the Z axis at 9.8 m/s². When the device is tilted, the gravity projections redistribute among the axes — from these projections, the tilt angle can be calculated with an accuracy of up to 0.1 degrees. To detect motion without the influence of gravity, a high-pass filter is used to separate the dynamic component of acceleration (the device’s own movement) from the static component (gravity).
On Android, access to the accelerometer is provided through the SensorManager class and the SensorEventListener interface. The application obtains the SENSOR_SERVICE system service, requests the TYPE_ACCELEROMETER sensor, and registers a listener with a specified update rate. The system calls onSensorChanged with each new measurement, providing an array of values: values[0] = X, values[1] = Y, values[2] = Z. Below is a complete example of reading accelerometer data in Kotlin.
val sensorManager = getSystemService(SENSOR_SERVICE) as SensorManager
val accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
val sensorEventListener = object : SensorEventListener {
override fun onSensorChanged(event: SensorEvent) {
val x = event.values[0]
val y = event.values[1]
val z = event.values[2]
// Calculating tilt angle
val pitch = Math.atan2(
x.toDouble(),
Math.sqrt(y.toDouble() * y + z.toDouble() * z)
)
// Updating UI with new angle
textViewAngle.text = "Tilt: ${Math.toDegrees(pitch)}°"
}
override fun onAccuracyChanged(
sensor: Sensor, accuracy: Int
) { }
}
sensorManager.registerListener(
sensorEventListener,
accelerometer,
SensorManager.SENSOR_DELAY_GAME
)
In the example, SensorManager.SENSOR_DELAY_GAME sets the update rate to ~50 Hz, optimal for games and interactive applications. For step counting, use SENSOR_DELAY_NORMAL (~5 Hz); for precise measurements, use SENSOR_DELAY_FASTEST (~200 Hz). In onSensorChanged, the event.values array contains the current sensor readings. Based on the X, Y, Z values, the pitch angle is calculated using atan2 — this is the basic formula for determining device orientation without using the orientation sensor. Remember to unregister the listener in onPause to save battery life.
private val alpha = 0.8f
private val gravity = FloatArray(3)
private val linearAcceleration = FloatArray(3)
override fun onSensorChanged(event: SensorEvent) {
// Low-pass filter (LPF) for gravity extraction
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0]
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1]
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2]
// Subtracting gravity — getting linear acceleration
linearAcceleration[0] = event.values[0] - gravity[0]
linearAcceleration[1] = event.values[1] - gravity[1]
linearAcceleration[2] = event.values[2] - gravity[2]
}
A low-pass filter with coefficient alpha extracts the gravitational component (static vector); subtracting it gives the device’s pure acceleration (linear acceleration). This is necessary for detecting motion without considering orientation — for example, detecting a step, shake, or impact. An alpha value of 0.8 means the filter passes ~20% of the new signal and retains 80% of the previous one — enough to smooth out noise without significant delay.
On iOS, access to the accelerometer is provided by the Core Motion framework through the CMMotionManager class. The application creates a manager instance and calls startAccelerometerUpdates with a queue and a handler. Data is returned as CMAccelerometerData, containing a CMAcceleration structure with x, y, and z fields. Below is an example of obtaining accelerometer data in Swift with noise filtering.
import CoreMotion
let motionManager = CMMotionManager()
motionManager.accelerometerUpdateInterval = 1.0 / 60.0
guard motionManager.isAccelerometerAvailable else { return }
motionManager.startAccelerometerUpdates(to: OperationQueue.current!) {
data, error in
guard let acceleration = data?.acceleration,
error == nil else { return }
// Values in g (1 g = 9.8 m/s²)
let magnitude = sqrt(
acceleration.x * acceleration.x +
acceleration.y * acceleration.y +
acceleration.z * acceleration.z
)
// If magnitude > 2.5 g — shake detected
if magnitude > 2.5 {
DispatchQueue.main.async {
self.handleShake()
}
}
}
In the example, accelerometerUpdateInterval is set to 1/60 sec (~60 Hz) — optimal for smooth animation and games. The isAccelerometerAvailable method checks whether the sensor is available on the device. Acceleration values are returned in g units (where 1 g = 9.8 m/s²). The magnitude vector is calculated as the Euclidean norm of the three components — if the value exceeds 2.5 g, it is interpreted as a device shake. To stop updates, always call stopAccelerometerUpdates when leaving the screen.
The accelerometer is used in a wide range of mobile applications. The most obvious scenario is automatic screen rotation: the system switches between portrait and landscape orientation based on accelerometer data. In games, the accelerometer serves as a control input — tilting the device turns the steering wheel or moves the character. Fitness apps count steps based on characteristic acceleration peaks during walking. Below is a table of typical scenarios and sensor requirements.
| Scenario | Frequency (Hz) | Accuracy | Filtering |
|---|---|---|---|
| Auto screen rotation | 5–10 | Low | LPF |
| Step counting | 20–50 | Medium | HPF + peak detector |
| Games (racing) | 50–200 | High | Calibration + LPF |
| Camera stabilization | 200–1000 | Maximum | Complementary filter |
| Gesture recognition | 50–100 | Medium | HPF + threshold detector |
When implementing an accelerometer, keep in mind that device heating and sensor aging can affect reading accuracy. For critical measurements (video stabilization, compass), it is recommended to also use the gyroscope and magnetometer as part of sensor fusion.
Accelerometers are subject to several types of errors: zero bias — when the sensor shows a non-zero value at rest; scale factor error — when sensitivity differs across axes; and measurement noise, which reduces the accuracy of a single reading. MEMS sensors are calibrated during manufacturing, but over time parameters can drift due to temperature and mechanical stress. For compensation in the application, a simple calibration can be implemented: at rest, record the average value (bias) and subtract it from all subsequent measurements. More accurate calibration requires rotating the device along all axes — this method is called six-point calibration and achieves an error of less than 0.5%.
Frequently Asked Questions
An accelerometer in a smartphone is a MEMS sensor about 1 mm in size that measures acceleration along three axes. It determines device orientation (portrait or landscape), shaking, steps, and movement without using external sources.
An accelerometer measures linear acceleration (including gravity), while a gyroscope measures angular velocity (rotation). An accelerometer determines orientation, a gyroscope detects rotation. Together they provide accurate motion tracking in space (sensor fusion).
Use SensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) to obtain the sensor, then registerListener with a SensorEventListener. In onSensorChanged, the event.values array contains X, Y, Z values in m/s². Always unregister in onPause.
Calculate magnitude = sqrt(x² + y² + z²). If the magnitude exceeds 2–3 g (after filtering gravity), the device has been shaken. For iOS, use CMMotionManager with a threshold of 2.5 g; for Android, use Sensor.TYPE_LINEAR_ACCELERATION with a threshold of 15 m/s².
Yes, for a simple calibration place the device on a flat surface, record the average readings for each axis over 2–3 seconds, and subtract these values from all subsequent measurements. This compensates for zero bias but not for scale error.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also