This article is a collection of the following pieces of information:
Most modern smartphones have an accelerometer that can measure forces in three directions, or along three axes, which are usually labelled x, y and z. The accelerometer in your phone measures the g-force it experiences in each of these three axes. Even when your phone seems to be at rest the accelerometer will still detect acceleration due to gravity (9.81 m/s/s ) and we can view this with an Android app.
Using Thunkable we can detect if the phone is moved up or down, forwards or backwards, or, left or right.
The accelerometer has two events and four properties that you can work with.
In this app we just want to read data from the sensor and detect when the phone has been shaken. To build one yourself you need the following components.
The first thing to do is chech whether or not the phone has an accelerometer in the first place. If not you can notify your user about this:
Alternatively, if your user must have an accelerometer to use your app properly you can notify the user and then close the app by doing the following:
It is also possible to turn on and off the sensor. Here, this is achieved with a Checkbox:
Next we can use the
Accelertion Changed event to display the accelerations in each direction:
Finally, we show a notification and make the phone vibrate when the phone is shaken:
Scott Ferguson’s video is excellent
The App Inventor book has information on the Accelerometer starting on page 356
You can download the sample app and source here: