This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 52).
A library that provides access to a device's accelerometer, barometer, motion, gyroscope, magnetometer, and pedometer.
expo-sensors
provide various APIs for accessing device sensors to measure motion, orientation, pressure, magnetic fields, ambient light, and step count.
-
npx expo install expo-sensors
If you are installing this in an existing React Native app, start by installing expo
in your project. Then, follow the additional instructions as mentioned by the library's README under "Installation in bare React Native projects" section.
You can configure expo-sensors
using its built-in config plugin if you use config plugins in your project (EAS Build or npx expo run:[android|ios]
). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect.
{
"expo": {
"plugins": [
[
"expo-sensors",
{
"motionPermission": "Allow $(PRODUCT_NAME) to access your device motion"
}
]
]
}
}
Name | Default | Description |
---|---|---|
motionPermission | "Allow $(PRODUCT_NAME) to access your device motion" | Only for: iOS A string to set the |
import * as Sensors from 'expo-sensors';
// OR
import {
Accelerometer,
Barometer,
DeviceMotion,
Gyroscope,
LightSensor,
Magnetometer,
MagnetometerUncalibrated,
Pedometer,
} from 'expo-sensors';
Starting in Android 12 (API level 31), the system has a 200Hz limit for each sensor updates.
If you need an update interval of less than 200Hz, you must add the following permissions to your app.json inside the expo.android.permissions
array.
Android Permission | Description |
---|---|
Allows an app to access sensor data with a sampling rate greater than 200 Hz. |
The following usage description keys are used by this library:
Info.plist Key | Description |
---|---|
A message that tells the user why the app is requesting access to the device’s motion data. |
Learn how to configure the native projects in the installation instructions in the expo-sensors
repository.
For more information, please see the documentation for the sensor you are interested in:
Measures device acceleration on all platforms.
Measures pressure on Android and iOS platforms.
Measures device motion on all platforms.
Measures device rotation on all platforms.
Measures magnetic fields on Android and iOS platforms.
Measures ambient light on Android platform.
Measures steps count on Android and iOS platforms.