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

Expo Barometer iconExpo Barometer

A library that provides access to device's barometer sensor.

Android
iOS (device only)
Included in Expo Go
Recommended version:
~56.0.6

Barometer from expo-sensors provides access to the device barometer sensor to respond to changes in air pressure, which is measured in hectopascals (hPa).

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.

Usage

Basic Barometer usage
import { useState } from 'react'; import { StyleSheet, Text, TouchableOpacity, View, Platform } from 'react-native'; import { Barometer } from 'expo-sensors'; export default function App() { const [{ pressure, relativeAltitude }, setData] = useState({ pressure: 0, relativeAltitude: 0 }); const [subscription, setSubscription] = useState(null); const toggleListener = () => { subscription ? unsubscribe() : subscribe(); }; const subscribe = () => { setSubscription(Barometer.addListener(setData)); }; const unsubscribe = () => { subscription && subscription.remove(); setSubscription(null); }; return ( <View style={styles.wrapper}> <Text>Barometer: Listener {subscription ? 'ACTIVE' : 'INACTIVE'}</Text> <Text>Pressure: {pressure} hPa</Text> <Text> Relative Altitude:{' '} {Platform.OS === 'ios' ? `${relativeAltitude} m` : `Only available on iOS`} </Text> <TouchableOpacity onPress={toggleListener} style={styles.button}> <Text>Toggle listener</Text> </TouchableOpacity> </View> ); } const styles = StyleSheet.create({ button: { justifyContent: 'center', alignItems: 'center', backgroundColor: '#eee', padding: 10, marginTop: 15, }, wrapper: { flex: 1, alignItems: 'stretch', justifyContent: 'center', paddingHorizontal: 20, }, });

API

import { Barometer } from 'expo-sensors';

No API data file found, sorry!

Units and providers

OSUnitsProviderDescription
iOShPaCMAltimeterAltitude events reflect the change in the current altitude, not the absolute altitude.
AndroidhPaSensor.TYPE_PRESSUREMonitoring air pressure changes.
WebThis sensor is not available on the web and cannot be accessed. An UnavailabilityError will be thrown if you attempt to get data.