Linear Acceleration Sensor in Mobile Apps

Use the virtual linear acceleration sensor to read motion-only data — accelerometer minus gravity — on iOS and Android.

Timothy Lindblom

Founder, Newly

Linear acceleration is the accelerometer signal with gravity removed. It is the sensor you actually want most of the time, because it cleanly answers "is the device being moved?" without needing to subtract a 9.81 m/s² baseline yourself.

Key Takeaways

  • Linear acceleration is in m/s² and reads ~0 on a stationary device.
  • It is virtual — the OS derives it from the accelerometer + gyroscope.
  • On iOS it is `CMDeviceMotion.userAcceleration`; on Android it is `Sensor.TYPE_LINEAR_ACCELERATION`.
  • Use it for shake detection, step counting, gesture recognition and impact detection.

Linear Acceleration at a Glance

0 m/s²
At rest
3 axes
Motion-only signal
50–200 Hz
Common rate
Virtual
No dedicated chip

What It Is & How It Works

What it is. The fused, gravity-removed component of the accelerometer signal. Whatever number you read is purely the device being shaken, walked with, or struck.

How it works. The OS uses the gyroscope to estimate the gravity direction, subtracts it from the raw accelerometer, and exposes the residual as a 3-axis vector.

Units & signal. Both iOS and Android report in m/s². iOS additionally reports user acceleration in g via Core Motion if you prefer.

What You Can Build With It

Shake to refresh / undo

Detect bursts of motion magnitude without needing to subtract gravity yourself.

Example: A drawing app that erases on shake.

Step / activity counting

Cleaner peaks than raw accelerometer make pedometer logic simpler and more reliable.

Example: A simple step counter for a wellness app.

Gesture recognition

Gestures like wrist-flick or arm-swing show up as distinctive acceleration patterns.

Example: A "wave to dismiss" alert in a hands-free cooking app.

Impact and drop detection

Spikes in magnitude are clear because the gravity baseline is gone.

Example: A delivery-driver app that flags "package dropped" events.

Permissions & Setup

Same Motion & Fitness prompt as the accelerometer on iOS; no permission required on Android.

iOS · Info.plist

  • NSMotionUsageDescription

Android · AndroidManifest.xml

No special permission keys required.

Code Examples

Setup

  • Expo: `npx expo install expo-sensors` (use `DeviceMotion.acceleration`)
  • iOS: `CMDeviceMotion.userAcceleration`
  • Android: `Sensor.TYPE_LINEAR_ACCELERATION` (API 9+)
import { useEffect, useState } from 'react';
import { DeviceMotion } from 'expo-sensors';

export function useLinearAcceleration() {
  const [data, setData] = useState({ x: 0, y: 0, z: 0 });

  useEffect(() => {
    DeviceMotion.setUpdateInterval(50);
    const sub = DeviceMotion.addListener(({ acceleration }) => {
      if (acceleration) setData(acceleration);
    });
    return () => sub.remove();
  }, []);

  return data;
}

Tip: With Newly, you describe the feature you want and the AI agent wires up the sensor, permissions, and UI for you. Try it free.

Best Practices

  • Default to linear acceleration for motion questions

    Reach for it before raw accelerometer whenever you want to know "is something moving?".

  • Use magnitude for triggers

    `sqrt(x²+y²+z²)` collapses three axes into one threshold-able number.

  • Pair with the gyro for gestures

    Acceleration alone confuses "moved up" with "rotated up". Add gyroscope to disambiguate.

  • Sample at 50 Hz for human gestures

    Going higher rarely improves accuracy and burns more battery.

Common Pitfalls

Using it on devices without fusion

Older Androids may not implement the virtual sensor. `getDefaultSensor` returns null.

Mitigation: Fall back to raw accelerometer with manual gravity subtraction (low-pass filter).

Treating thresholds as universal

A 1.5 g shake on a phone is a normal walk-step on a wrist-mounted device.

Mitigation: Calibrate thresholds per form factor or per user with a short calibration step.

Sampling on the JS thread

High-rate state updates in React Native can block UI animations.

Mitigation: Throttle setState to 10–20 Hz; or use Reanimated worklets to keep maths off JS.

When To Use It (And When Not To)

Good fit

  • Shake / drop / tap-on-back detection
  • Pedometer logic where the platform pedometer is unavailable
  • Gesture recognition combined with the gyroscope
  • Activity intensity (low/medium/high) heuristics

Look elsewhere if…

  • Tilt or "which way is down" — use gravity sensor
  • Absolute orientation — use rotation vector / device motion attitude
  • Sub-mm displacement — accumulated noise is too large
  • Background streaming on iOS without an entitlement

Frequently Asked Questions

How is this different from the accelerometer?

The accelerometer reports acceleration including gravity. Linear acceleration reports only the user-induced motion — the gravity component has already been removed for you.

How do I detect a tap on the back of the device?

Look for a single short magnitude spike (>3 g, <50 ms) followed by quiet. iOS additionally exposes BackTap via accessibility shortcuts.

Why are my readings non-zero when the phone is still?

There is always residual noise after gravity subtraction (typically <0.05 g). Apply a deadzone before triggering.

Can I use this for VR / AR pose tracking?

Use it as one input, but always fuse with gyro and platform pose APIs (ARKit / ARCore) — integrating acceleration alone drifts within a couple of seconds.

Build with the Linear Acceleration on Newly

Ship a linear acceleration-powered feature this week

Newly turns a description like “use the linear acceleration to shake to refresh / undo into a real React Native app — permissions, native modules and UI included. Full source code is yours, and you can publish to the App Store and Google Play directly from the dashboard.

Start Building Your App

Want a deeper dive on the underlying APIs? See Expo Sensors, Apple Core Motion and Android sensor framework.

Continue Learning