Barometer in Mobile Apps: Pressure and Altitude
Use the barometric pressure sensor in iOS and Android apps to estimate altitude, detect floor changes and improve weather features.
Most modern flagship phones include a barometer. It measures atmospheric pressure, which sounds boring until you remember that pressure changes with altitude — about 12 Pa per metre near sea level. That makes the barometer the easiest way to detect when a user climbs stairs, changes floors in a building or gains elevation on a hike.
Key Takeaways
- The barometer reports atmospheric pressure in hectopascals (hPa) — typical sea-level reading is ~1013 hPa.
- Subtracting two pressure readings gives you a relative altitude change accurate to ~0.3 m.
- Absolute altitude requires a reference (e.g. local weather station QNH) — the sensor alone cannot tell you "metres above sea level".
- Not every device has one. Always feature-detect before relying on the barometer.
Barometer at a Glance
What It Is & How It Works
What it is. A MEMS pressure sensor that reports the local air pressure. Because pressure decreases predictably with altitude, the sensor is widely used to detect altitude change and (on iOS) classify floors.
How it works. You subscribe to a pressure stream. iOS Core Motion exposes a higher-level CMAltimeter that integrates pressure into a relative-altitude reading and even dispatches floor-change events.
Units & signal. Pressure is reported in hPa (= mbar). Relative altitude in metres. Absolute altitude requires a known reference pressure.
What You Can Build With It
Floor / staircase detection
Detect when the user climbs or descends a floor in a building — typically a 3–4 m altitude change.
Example: A wellness app that nudges the user to take the stairs more often.
Hiking and outdoor altitude
Track elevation gain on a hike with sub-metre resolution that GPS alone cannot match.
Example: A hiking tracker that shows total ascent in metres.
Indoor positioning
Combine barometric floor estimates with Wi-Fi or BLE beacons for "Floor 3, North wing" indoor wayfinding.
Example: A hospital wayfinding app that picks the right floor on the map.
Local weather features
Track pressure trends to give a "rain in the next hour" hint or a falling-pressure storm warning.
Example: A barometer-trend chart in a weather app.
Permissions & Setup
iOS reads the barometer through Core Motion, so the Motion & Fitness prompt applies. Android requires no runtime permission.
iOS · Info.plist
NSMotionUsageDescription
Android · AndroidManifest.xml
No special permission keys required.
Code Examples
Setup
- Expo: `npx expo install expo-sensors`
- iOS: use `CMAltimeter` for relative altitude + floor events
- Android: register a listener for `Sensor.TYPE_PRESSURE` and convert with `getAltitude`
import { useEffect, useState } from 'react';
import { Barometer } from 'expo-sensors';
export function useBarometer() {
const [data, setData] = useState({ pressure: 0, relativeAltitude: 0 });
useEffect(() => {
Barometer.setUpdateInterval(1000);
const sub = Barometer.addListener(setData); // pressure: hPa
return () => sub.remove();
}, []);
return data;
}Tip: With Newly, you describe the feature you want and the AI agent wires up the sensor, permissions, and UI for you. Try it free.
Best Practices
Use relative, not absolute, altitude
Compare the current reading to a starting reading to track elevation change. Absolute altitude needs a reference pressure that varies with the weather.
Sample slowly
Pressure changes on the timescale of seconds, not milliseconds. 1 Hz is plenty for floor detection; 0.2 Hz works for weather trends.
Smooth aggressively
A 5–10 sample moving average eliminates noise from doors opening, fans, and the user holding their phone in different orientations.
Feature-detect
A meaningful share of devices lack a barometer. Always check `isRelativeAltitudeAvailable()` (iOS) or null sensor (Android).
Common Pitfalls
Treating absolute altitude as accurate
Without a reference, "altitude from pressure" can be off by ±100 m as the weather changes.
Mitigation: Track only delta-altitude unless you have a known reference pressure.
Air-conditioned buildings
Strong HVAC airflow and rapid door cycles cause false floor-change events.
Mitigation: Smooth over 30–60 seconds before reporting a floor change; ignore changes <2 m.
Going outside flips the baseline
Pressure can shift several hPa within minutes when the user moves in/out of a building or weather front.
Mitigation: Reset your baseline whenever you detect a sustained pressure change beyond an expected window.
Battery from over-sampling
Some implementations wake the sensor for every read.
Mitigation: Use `SENSOR_DELAY_NORMAL` (Android) or 0.5–1 s (iOS); turn off when off-screen.
When To Use It (And When Not To)
Good fit
- Floor detection in indoor wayfinding apps
- Elevation gain in fitness / hiking apps
- Local pressure trends in weather apps
- Augmenting GPS altitude with sub-metre sensitivity
Look elsewhere if…
- Apps that need to run on every device — feature-detect first
- Absolute "metres above sea level" without a reference pressure
- Continuous high-frequency monitoring
- Replacing barometric data services for serious meteorology
Frequently Asked Questions
Does my phone have a barometer?
Most flagship Android phones and every iPhone since the 6 do. Check at runtime with `CMAltimeter.isRelativeAltitudeAvailable()` or by asking SensorManager for `TYPE_PRESSURE`.
How accurate is altitude from pressure?
Relative altitude is good to about 0.3–1 m, which is far better than GPS. Absolute altitude needs a reference pressure and can be 100 m off otherwise.
Can I get floor changes for free on iOS?
Yes — `CMAltimeter.startAbsoluteAltitudeUpdates` and the related floor-change events do the smoothing and detection for you.
Why does my pressure jump when I open a door?
Pressure differentials between rooms and outside cause real, measurable spikes. Smoothing or ignoring spikes shorter than 5 seconds usually fixes it.
Build with the Barometer on Newly
Ship a barometer-powered feature this week
Newly turns a description like “use the barometer to floor / staircase detection” into a real React Native app — permissions, native modules and UI included. Full source code is yours, and you can publish to the App Store and Google Play directly from the dashboard.
Want a deeper dive on the underlying APIs? See Expo Sensors, Apple Core Motion and Android sensor framework.
