Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

jack hamilton
jack hamilton
5,609 Points

How to I measure the vertical travel of my phone?

So I would like to make a app which when I strap it to my car I can see the vertical travel of my car to sort of measure it's suspension.

I believe this is possible in IOS although I am not sure how I would do it in Android.

I don't care about the side to side or the tilt of the phone just up and down.

Preferably the read out would be in centimeters.

Does anyone know where I should go to start researching this?

Thank you!

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

What you want to use is the phone's accelerometer. It won't give you position directly but you can calculate it. Computing position from acceleration uses fairly standard math formulas but there are some subtleties with real-world instruments.

https://developer.android.com/guide/topics/sensors/sensors_overview.html https://developer.android.com/guide/topics/sensors/sensors_motion.html

jack hamilton
jack hamilton
5,609 Points

Thank you, so how do you know how accurate it could be / any tutorials on it? Thank you.