Calculating Indoor Elevation Gain with Phone Barometer
I was inspired to try the Everesting challenge in my building stairwell after reading a story about another ultrarunner completing this…
Calculating Indoor Elevation Gain with Phone Barometer

I was inspired to try the Everesting challenge in my building stairwell after reading a story about another ultrarunner completing this feat.
Besides the physical challenge, there is the question of how to measure elevation gain without access to GPS or precise measurements of building height.
Here, I describe the setup I used to achieve this using my phone’s built-in barometric sensor. This setup allowed me to create a Strava activity with realistic-looking elevation.
The key to making this work is the barometric formula, or its simplified version called the isothermal atmosphere model:
def get_altitude(measured_pressure, sea_level_pressure, temperature_celsius):
R = 287.05 # Specific gas constant for dry air (J/(kg·K))
g = 9.80665 # Gravitational acceleration (m/s²)
T = temperature_celsius + 273.15 # Convert to Kelvin
altitude = (R * T / g) * math.log(sea_level_pressure / measured_pressure)
return altitude
This requires knowing several parameters:
- Measured pressure: The raw value of pressure in hPa as recorded by either a watch or the phone.
- Sea level pressure: The sea level pressure at the current location, which varies continuously.
- Temperature: The current temperature.
Measuring Pressure
This surprisingly simple task does not work out of the box because my Polar watch records elevation instead of raw pressure data, and the barometric apps I tried use GPS to calculate elevation rather than relying solely on pressure. Thanks to ChatGPT, I was able to write a minimally working barometric pressure app that simply creates a CSV with pressure values recorded every second.

Sea Level Pressure and Temperature
Next came the sea level pressure and temperature. Several options are available; I chose the Tomorrow.io API. I wrote a Lambda function that retrieves the pressure every 10 minutes and stores it in DynamoDB.
I recorded the exact time and heart rate with my Polar watch. Time is the key, allowing me to merge the TCX from my watch, the pressure recordings from the phone, and the reference pressure from Tomorrow.io.
Plugging the values into the isothermal atmosphere model, I get a CSV with the elevation for each timestamp:
epoch,elevation
1760490895,36.50804612483181
1760490896,36.501124726680644
1760490897,36.48036056516906
We can fill in the TCX with these altitude values, but Strava requires recording the (lat, lon) positions in addition to altitude to render activity pace and distance accurately.
Mapping Position in a Zigzag Stairwell
My stairwell is zigzag-shaped, so I needed to measure the stairs physically to get the following values:
STEPS_PER_FLIGHT = 11 # Number of steps per flight of stairs
STEP_HEIGHT_CM = 15 # Elevation per step
STEP_DEPTH_CM = 28 # Horizontal distance of each step
I start with a fixed (lat, lon) position and, using the elevation CSV above, approximate my position. This introduces minor errors but is reasonably accurate.

Ensuring Accurate Elevation
The total height can be approximated by multiplying the height of each step by the number of steps and floors. In my case:
15 cm × 22 steps × 31 floors = 102.3 m
Open Buildings 2.5D Temporal Dataset gives building heights. In my case, it reports 90 meters, which is less than the actual building height:

Finally, the start location height must be considered. Using the isothermal formula, I calculated a start height of 36.5 meters, which seems reasonable. I fixed this as the start elevation to correct for potential pressure-based elevation errors.
I was surprised by how precise the result is. In fact, GPS-based elevation is often considerably worse than barometric-based elevation, even when GPS is available:

메타데이터
- post_id
- f3a36d45dea3
- slug
- calculating-indoor-elevation-gain-with-phone-barometer-f3a36d45dea3
- url
- https://medium.com/@arbatov/calculating-indoor-elevation-gain-with-phone-barometer-f3a36d45dea3
- canonical_url
- https://medium.com/@arbatov/calculating-indoor-elevation-gain-with-phone-barometer-f3a36d45dea3
- author_url
- https://medium.com/@arbatov
- status
- ok
- fetched_at
- 2026-06-12 18:14:10