HomeGuidesReferenceLearn

Reference version

ArchiveExpo SnackDiscord and ForumsNewsletter

Expo Sensors iconExpo Sensors

GitHub

npm

A library that provides access to a device's accelerometer, barometer, motion, gyroscope, magnetometer, and pedometer.


expo-sensors provides various APIs for accessing device sensors to measure motion, orientation, pressure, magnetic fields, ambient light, and step count.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

Installation

Terminal
npx expo install expo-sensors

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

API

import * as Sensors from 'expo-sensors';
// OR
import {
  Accelerometer,
  Barometer,
  DeviceMotion,
  Gyroscope,
  LightSensor,
  Magnetometer,
  MagnetometerUncalibrated,
  Pedometer,
} from 'expo-sensors';

Permissions

Android

Starting in Android 12 (API level 31), the system has a 200ms limit for each sensor updates.

If you need an update interval of less than 200ms, you must add the following permissions to your app.json inside the expo.android.permissions array.

Android PermissionDescription

HIGH_SAMPLING_RATE_SENSORS

Allows an app to access sensor data with a sampling rate greater than 200 Hz.

Are you using this library in a bare React Native app?

Learn how to configure the native projects in the installation instructions in the expo-sensors repository.

Available sensors

For more information, please see the documentation for the sensor you are interested in:

Accelerometer

Measures device acceleration on all platforms.

Barometer

Measures pressure on Android and iOS platforms.

DeviceMotion

Measures device motion on all platforms.

Gyroscope

Measures device rotation on all platforms.

Magnetometer

Measures magnetic fields on Android and iOS platforms.

LightSensor

Measures ambient light on Android platform.

Pedometer

Measures steps count on Android and iOS platforms.