Detecting Tilt (and a Little Background Physics)

The accelerometer can detect very subtle accelerations in three directions. One such acceleration is the constant one from gravity. Think back to your physics class (or think forward if you haven’t gotten there yet): Gravity constantly applies a downward acceleration to every object on Earth, even if that object is sitting completely still. If that object happens to have a three-axis accelerometer, as smartphones do, that device can detect that acceleration.

Take a look at Figure 10.12. On the left is a phone lying flat on a table, not moving. The only acceleration present is gravity, which is pulling straight down (the green arrow). The blue axes in the middle show the direction of the accelerometer’s ...

Get Learning MIT App Inventor: A Hands-On Guide to Building Your Own Android Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.