This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo DeviceMotion iconExpo DeviceMotion

A library that provides access to a device's motion and orientation sensors.

Android
iOS
Web
Included in Expo Go
Recommended version:
~56.0.6

DeviceMotion from expo-sensors provides access to the device motion and orientation sensors. All data is presented in terms of three axes that run through a device. According to portrait orientation: X runs from left to right, Y from bottom to top and Z perpendicularly through the screen from back to front.

Installation

Terminal
- npx expo install expo-sensors
- yarn expo install expo-sensors
- pnpm expo install expo-sensors
- bun expo install expo-sensors

If you are installing this in an existing React Native app, make sure to install expo in your project.

Configuration in app config

You can configure DeviceMotion from expo-sensor using its built-in config plugin if you use config plugins in your project (Continuous Native Generation (CNG)). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect. If your app does not use CNG, then you'll need to manually configure the library.

Example app.json with config plugin

app.json
{ "expo": { "plugins": [ [ "expo-sensors", { "motionPermission": "Allow $(PRODUCT_NAME) to access your device motion." } ] ] } }

Configurable properties

NameDefaultDescription
motionPermission"Allow $(PRODUCT_NAME) to access your device motion"
Only for: 
iOS

A string to set the NSMotionUsageDescription permission message.

Are you using this library in an existing React Native app?

If you're not using Continuous Native Generation (CNG) or you're using native ios project manually, then you need to configure NSMotionUsageDescription key in your native project to access DeviceMotion stats:

ios/[app]/Info.plist
<key>NSMotionUsageDescription</key> <string>Allow $(PRODUCT_NAME) to access your device motion</string>

API

import { DeviceMotion } from 'expo-sensors';

No API data file found, sorry!

Permissions

iOS

The following usage description keys are used by this library:

Info.plist keyDescription

NSMotionUsageDescription

A message that tells the user why the app is requesting access to the device’s motion data.