Measure the Height of a Building With an ... Accelerometer?

The iPhone makes it easy to do all kinds of cool physics. Like, say, use the change in velocity in an elevator to measure the height of a building.
Image may contain Home Decor Human Person Window Curtain Shutter and Window Shade
Getty Images

All products featured on WIRED are independently selected by our editors. However, we may receive compensation from retailers and/or from purchases of products through these links.

Smartphones are pretty amazing when you think about it. Besides letting you watch Star Wars whenever you want, answer any question instantly, and play Super Mario Run during staff meetings, smartphones make it super-easy to learn about physics.

I've already shown you how to use your camera to figure out how fast your airplane is going, and last week I explained how to use a phone's barometer to measure the height of a building. Now I will show you how to measure distance using the accelerometer, just like I said I would at the end of that post.

An accelerometer measures acceleration, of course. But what is acceleration? Let me start with a definition in one dimension (so you don't have to worry about those annoying, but oh-so-useful, vectors):

This equation states that acceleration is equal to the change in velocity divided by the change in time. Looking at it differently, if I know that an object has a certain acceleration for a certain amount of time, I can determine the change in velocity for that object. To do this, I need to know the object's velocity before it accelerated. In general, if I know the velocity at one time (I will call this v1) then I can find the velocity at the next (v2):

Now imagine that your phone records the value of the acceleration 100 times every second. If the acceleration remained constant during each of interval of 0.01 seconds, you could calculate the velocity after each of these tiny 0.01 second intervals. If you keep doing this, you would have a plot of velocity vs. time (assuming you knew that very first velocity to start with).

OK, let's do this. I know you've got your phone handy, and you might even have an elevator nearby. (I will use a small car on a track so I can accurately measure its position.) You need some way of recording the acceleration. Many iOS apps do this, but I like NCSU MyTech.

Got everything? Good. Summon the elevator. When it arrives, put your phone on the floor, press record on your app, and ride all the way to the top. If there are people in the elevator, act like you're doing something important and they'll leave you alone. Once you reach the top floor, stop recording and grab your phone. Save the file and email it to yourself.

Before proceeding, we must deal with a small problem. If you place your phone on the floor of a stationary elevator, you'll get an acceleration reading of around 9.8 m/s2. Why? Because of Einstein's equivalence principle. It states that the phone can't tell a difference between acceleration and a gravitational field. To fix this you must measure the initial acceleration and subtract it from every reading. This should give you a starting acceleration of 0 m/s2.

Now for a calculation. Load your data into a spreadsheet and subtract the stationary acceleration. We'll use this to determine the velocity from the acceleration and time values. It should look something like this:

After loading the file into a spreadsheet, I deleted the acceleration columns I didn't need. My phone accelerated in the y-direction, but if you put your phone face-up in the elevator it probably accelerated in the z-direction. To calculate the velocity, I entered a value of zero in the first cell since it started from rest. For every other cell in that column, you simply enter the previous value, plus the acceleration multiplied by the change in time.

OK, let's plot it and see the velocity. You can create a plot in your spreadsheet, but I will use an online plotter. And I will cheat. Since I am using a cart on a track, I can determine the velocity with this Vernier tracking system. Here is my calculated and measured velocity together.

You will notice that the two velocity plots are close, but not identical. In particular, my calculated velocity continues increasing after the cart should have stopped. I suspect this is my fault. I used a rubber band to affix my phone to the cart, and it might have shifted a bit, creating acceleration in the y-direction because of the gravitational field. Still, it's pretty close.

But I don't want to find the velocity of the elevator (or in my case, a cart). I want to find the position. We can use the velocity data to do this. Using the definition of average velocity, I can again solve for the new position based on the old position and the average velocity:

Yes, this leads to a small problem. Strictly speaking, I should use the average velocity, not the velocity at some particular time. However, with a small enough time interval, this should be approximately true. Let's try it and see what happens. Here is the position plot for both the calculation from the iPhone data and the motion encoder:

Again, the iPhone data suggests the cart keeps moving after it should have stopped. But overall, the method worked well.

Homework
  • Try this on an actual elevator. Compare the height calculated using the accelerometer with the height calculated with the barometer.
  • One problem with the NCSU MyTech App is it gives the acceleration data down to just 0.01 m/s2. What happens when you use a different acceleration recorder? Do you get a better answer? Some sensor recording apps (like SensorLog) also record the orientation of the phone. You might find that useful here.
  • The velocity and position calculations both use one specific value, not an average, for acceleration. What happens if you use three acceleration values to determine the average acceleration and use that value to find the new velocity (and do the same for the position calculations)? See if that gives a better position value.