How to use the accelerometer in your Expo app, in short
Install expo-sensors, check that the sensor exists with Accelerometer.isAvailableAsync(), then call Accelerometer.addListener with a callback. Every update gives you an object with x, y and z, plus a timestamp in seconds. The axis values are in g, a unit where 1g equals the pull of Earth's gravity, 9.81 m/s^2. When you leave the screen, call remove() on the subscription you got back.
That is the whole core. The rest of this guide is about the parts that decide whether the feature feels good or drains the battery: what the numbers actually mean, how fast to sample, how to turn raw readings into a shake or a tilt, and what changes when you want steps instead.
expo-sensors at a glance (SDK 58)
| Question | Answer |
|---|---|
| Install | npx expo install expo-sensors |
| Accelerometer platforms | Android, iOS (physical device only), Web |
| Works in Expo Go? | Yes for the accelerometer. Pedometer is not available in Expo Go on Android |
| Units | g on each axis (1g = 9.81 m/s^2), timestamp in seconds |
| Rate control | Accelerometer.setUpdateInterval(ms) |
| Cleanup | subscription.remove() |
| Also in the package | Barometer, DeviceMotion, Gyroscope, LightSensor (Android only), Magnetometer, Pedometer |
Step 1: Install expo-sensors
Run npx expo install expo-sensors. On SDK 58 that gives you the 58.0.x line. Use npx expo install rather than a plain npm install so the version matches your SDK.
The accelerometer is included in Expo Go, so you can try it on your phone right away. You still ship it in a normal [EAS build](/blog/eas-build-guide-for-expo-apps). One package covers every motion sensor, so if you later want the gyroscope or the step counter, there is nothing new to install.
Step 2: Subscribe, read x, y and z, and clean up
In a component, subscribe inside a useEffect and return a cleanup function that calls remove(). The pattern looks like this in words: on mount, await isAvailableAsync; if it is true, keep the subscription that addListener returns; on unmount, call subscription.remove(). If you skip the cleanup, every visit to the screen stacks another listener, and your callback runs more and more often.
What the axes mean is where most confusion starts. The values include gravity. A phone lying flat and still on a table does not read zero on all three axes. Gravity shows up on the axis that points up or down, so the total of the three axes sits around 1g even when nothing is moving. Movement shows up as changes on top of that.
Reading accelerometer values
| What you want | How to get it |
|---|---|
| Total force on the phone | Magnitude: the square root of x*x + y*y + z*z. Around 1 when the phone is still |
| Which way the phone is tilted | Compare x and y while the phone is roughly still, since gravity shifts between axes as it tilts |
| A sudden jolt or shake | A big jump in magnitude, well above 1, for a short moment |
| When a reading happened | The timestamp field, in seconds |
Step 3: Pick an update interval that fits the feature
Accelerometer.setUpdateInterval takes milliseconds between updates. 16 ms is roughly 60 updates a second, which suits a game or a live tilt control that redraws every frame. 1000 ms is one update a second, which is plenty for a slow indicator. Every update runs your callback in JavaScript and can trigger a re-render, so faster is not free.
- Games and tilt-to-steer controls: fast updates, and keep the work in the callback tiny.
- Shake to undo or shake to report a bug: a moderate rate is enough to catch a jolt.
- Showing a reading on a debug screen: slow updates, so the text is readable and the UI stays calm.
On Android 12 and later, the system caps each sensor at 200Hz. Going above that needs the HIGH_SAMPLING_RATE_SENSORS permission in expo.android.permissions in your app.json. Our take: almost no consumer app needs that. If you think you do, check first that a slower rate really breaks the feature.
Only listen while the screen that uses the data is open, and stop when it closes. If your feature should also back off when the phone is saving power, pair this with [Low Power Mode detection](/blog/how-to-check-battery-level-in-your-expo-app) and slow the interval down while it is on.
Step 4: Detect a shake
Shake detection is the most common real use of the accelerometer, and it is easy to get wrong in both directions: too sensitive and it fires when someone puts the phone in a pocket, too strict and nobody can trigger it. The approach that works is simple:
- Compute the magnitude of each reading.
- Treat it as a shake only when the magnitude goes clearly above 1g, since 1g is just gravity.
- Add a cooldown so one shake does not fire your action several times in a row.
- Give feedback when it fires, for example a short [haptic tap](/blog/how-to-add-haptic-feedback-to-your-expo-app), and always offer a normal button for the same action.
The exact threshold and cooldown are tuning choices, not fixed rules. Start with a value you pick, try it on a real phone in your hand, in a pocket and on a desk, and adjust. Shake should never be the only way to do something, because some users cannot shake a phone reliably and many will never discover the gesture.
Step 5: Count steps with Pedometer
If what you actually want is steps, do not try to count them from raw accelerometer data. Use Pedometer from the same package, which reads the system step counter. The API is small: isAvailableAsync, requestPermissionsAsync, watchStepCount for live updates, and getStepCountAsync for a past range. Each result has a steps number.
Pedometer gaps to plan around
| Gap | What it means for your app |
|---|---|
| Not in Expo Go on Android | Expo Go does not include the activity recognition permission the pedometer needs, so use a development build to test on Android |
| getStepCountAsync is iOS only | You can ask for steps between two dates on iPhone, not on Android |
| iOS keeps 7 days of step history | A start date older than that only returns what is still stored |
| No updates in the background | watchStepCount only delivers while your app is open. On Android, a background step solution needs Health Connect instead |
Ask for permission when the user turns on the step feature, not on first launch. Our guide to [requesting permissions](/blog/how-to-request-permissions-in-your-expo-app) covers the pattern. On iOS, set the motion usage message through the config plugin: add expo-sensors to plugins in app.json with a motionPermission string that says plainly why you need it. That text becomes the NSMotionUsageDescription the user sees, and it needs a new build to change.
Have Claude Code build it for you
Open your project in the Claude Code desktop app and describe the behavior you want, not just "add the accelerometer". Left alone, AI-written code tends to subscribe without cleanup, sample at the fastest rate for no reason, treat the resting 1g as movement, or try to count steps by hand. A prompt that heads those off:
Then add a line to your [CLAUDE.md](/blog/claude-md-for-expo-apps) such as "Sensors: always remove subscriptions on unmount, use the slowest interval that works, use Pedometer for steps" so a later session keeps the same rules.
The short version
To use the accelerometer in your Expo app: install expo-sensors, check isAvailableAsync, subscribe with addListener, and remove the subscription on unmount. Remember the readings are in g and include gravity, pick the slowest update interval that works, and test on a real iPhone. For steps, use Pedometer, and plan for its Android Expo Go and background gaps.
If you are building your first iOS app with Claude Code and Expo and want feedback on it before App Review, bring it to App Store Launch Club. Members share their builds and help each other get unstuck, and the [curriculum](/curriculum) covers the full path from first build to first users. If you are adding motion features, our guide to [haptic feedback](/blog/how-to-add-haptic-feedback-to-your-expo-app) pairs well with this one. Join at applaunchclub.co for $9 a month.
Short, practical drops on app ideas, validating fast, store listings, and passing app review. No spam, unsubscribe anytime.
Frequently asked questions
How do I use the accelerometer in Expo?
Install expo-sensors with npx expo install expo-sensors, import Accelerometer, check Accelerometer.isAvailableAsync(), then call Accelerometer.addListener with a callback. It receives { x, y, z, timestamp }. Call remove() on the returned subscription when the screen unmounts.
What units does the Expo accelerometer use?
Each axis is in g, where 1g equals 9.81 m/s^2, the pull of Earth's gravity. The readings include gravity, so a still phone shows a total of about 1g, not 0. The timestamp is in seconds.
Does the accelerometer work in the iOS simulator?
No. On iOS the accelerometer is device only. Test on a physical iPhone through Expo Go or a development build.
How do I change how often the accelerometer updates?
Call Accelerometer.setUpdateInterval with the number of milliseconds between updates, for example 16 for roughly 60 updates a second or 1000 for one a second. On Android 12 and later, going above 200Hz needs the HIGH_SAMPLING_RATE_SENSORS permission.
Why does Pedometer not work in Expo Go on Android?
Expo Go does not include the activity recognition permission the pedometer needs on Android. Create a development build to test step counting on Android.
Can I get past step counts in an Expo app?
On iOS, yes. Pedometer.getStepCountAsync(start, end) returns steps between two dates, and the system keeps about the past 7 days. It is not available on Android, and live updates from watchStepCount stop while the app is in the background.
Last reviewed by David on November 11, 2026


