# 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://1223006790-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)

## Adding an Accelerometer to your app

To add an Accelerometer to your app:

1. Navigate to the **Blocks** tab of your project.
2. Under the App Features heading, locate **Sensors**.&#x20;
3. Click the ⊕ symbol next to Sensor.
4. Select **Accelerometer** from the provided menu.
5. Click **Add**.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MMGsCOQmypJUYH0PDNJ%2F-MMGscus1Tmzgj_p_Z1B%2Fsensors.png?alt=media\&token=a7524d1d-1589-4802-94cb-df712fc62c3b)

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MMGsCOQmypJUYH0PDNJ%2F-MMGtN30eJmSdWNKCxqJ%2Fsensor-options.png?alt=media\&token=131b3d8e-7da1-48d0-96d0-a05ecadbbf32)

You will see a settings panel where you can set:

* The **Name** of the Accelerometer
* Whether the Accelerometer is **Enabled**
* Whether the **Sensitivity** of the Accelerometer is low, medium or high

You can either confirm your choices and create the Accelerometer, or delete the Accelerometer.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJXDtfqKd4NleIDcl1u%2F-MJXFIFJoujqdslgxPuQ%2Fimage.png?alt=media\&token=5a30f27d-ced0-42ec-afbb-c5ce677169fb)

### Change Settings of Accelerometer

You will see the sensors you have added to your app underneath the Sensors section of your blocks.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MMGsCOQmypJUYH0PDNJ%2F-MMGtPseGdJ7VyPZ-cB9%2Fshowallsensors.png?alt=media\&token=4356df80-9b33-4631-8848-bf1a5f7aeeb5)

\
If you click on the ⚙ icon next to your Accelerometer, you will be able to edit its settings as seen in the panels above. You can click on your Accelerometer's name to access its drawer of blocks.‌

## Properties

| Property    | Description                                                                                                  | Data Type                               |
| ----------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------- |
| Enabled     | Toggle whether the component is functioning in your app                                                      | True/False                              |
| Sensitivity | Set how sensitive the accelerometer is to movement, where higher sensitivity will react to smaller movements | Select from list: `[low, medium, high]` |

## 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://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2FkeWVRWFZi6q4HGEcZWRE%2Faccsh.png?alt=media\&token=6056fb20-afd0-4fdd-85ed-7c2390baf2e6)

#### 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://1223006790-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                                    |

### 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://1223006790-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://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY4-Gx3BWY9BSWsUzhb%2F-MY416xK0sWMbuZOP3pY%2FScreen%20Shot%202021-04-12%20at%208.42.32%20AM.png?alt=media\&token=ac113170-50e9-4eaf-913d-b091fffc56b5)

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