There is an Accelerometer object for that function. The object returns the values detected by the phone in several XYZ outputs.

Tips:
#1: The values are affected by the orientation of the phone....