# Accelerometer

## Getting Started&#x20;

The accelerometer sensor is used to measure the force of acceleration acting on the phone. The sensor reports this force for each of the three principal axes, the x axis, y axis and, the z axis. The values obtained from the sensor are in metres per second squared, $$m/s^2$$.<br>

![The x, y and z axes of a standard smartphone](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-LfAKkxNBiTf9-hUVp0f%2F-LfAKq11ubZzw9kwMlpm%2FScreenshot%202019-05-18%20at%2015.27.06.png?alt=media\&token=022db7f3-8781-4e58-b93f-aa810c0b5937)

## Blocks

### Events

#### Shaking

There may be some instances where you want to start an event by shaking your mobile device or when the mobile device is shook. There is a `Shaking` event that you can add to your blocks that has sensitivity levels of `high`, `medium` and `low`

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-Lh1JWi1_gyQBZ6MtKA3%2F-Lh1LjC3OuaypGyXXWQ4%2FScreen%20Shot%202019-06-10%20at%2010.06.07%20AM.png?alt=media\&token=5321f878-c87a-43a1-9107-a3134d26540b)

#### Changes

When the accelerometer sensor detects a change in the force acting on the phone the `Changes` event will be fired. Each time the event fires the four associated parameters will be updated.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-LfA1BsyDXYWwu4FI79m%2F-LfA4bXEe8dgrCQVB63V%2FScreenshot%202019-05-18%20at%2014.13.50.png?alt=media\&token=05386a4e-b02d-42a2-9214-c556fd52f860)

| **Parameter**   | Type   | Returns                                                      |
| --------------- | ------ | ------------------------------------------------------------ |
| `xAcceleration` | Number | Change in speed of the phone, along the x axis, in $$m/s^2$$ |
| `yAcceleration` | Number | Change in speed of the phone, along the y axis, in $$m/s^2$$ |
| `zAcceleration` | Number | Change in speed of the phone, along the z axis, in $$m/s^2$$ |
| `error`         | String | Error message from sensor                                    |

### Functions

#### Get Acceleration on X, Y, Z axes

You can get the values for xAcceleration, yAcceleration and zAcceleration at any time with the following blocks.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJXDtfqKd4NleIDcl1u%2F-MJXH_LCTx4ICLcvg4oZ%2Fimage.png?alt=media\&token=95d11816-9fc8-4b39-a9b4-6fe97b3bbf54)

### Properties

#### Enabled

By default the accelerometer sensor will be turned on, but you can use the `Enabled` property to read its current state and to change its state, i.e turn the sensor on and off.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXHM010I_0QovWUcLfk%2F-MXHQ3QBElO_EEIqeO1N%2Facc_enabled.png?alt=media\&token=e06b381a-9961-47e5-bf1b-7cd38a0290a5)

| Property      | Type | Default |
| ------------- | ---- | ------- |
| `set Enabled` | Bool | True    |
| `get Enabled` | Bool |         |

#### Sensitivity

You can use the Sensitivity blocks to set the sensitivity of the Accelerometer and get its current level of sensitivity.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJXDtfqKd4NleIDcl1u%2F-MJXHlXhUzJKBGrESLeB%2Fimage.png?alt=media\&token=906db9f1-c347-4cb1-819a-67567658e20c)

| Property          | Type                        | Default |
| ----------------- | --------------------------- | ------- |
| `set Sensitivity` | one of \[low, medium, high] | low     |
| `get Sensitivity` | one of \[low, medium, high] |         |
