AccelerometerSensor

Last Updated On 2021-07-16

Version 5MinSDK 7Tutorial Video

Non-visible component that can detect shaking and measure acceleration approximately in three dimensions using SI units (m/s2). The components are:

  • xAccel: 0 when the phone is at rest on a flat surface, positive when the phone is tilted to the right (i.e., its left side is raised), and negative when the phone is tilted to the left (i.e., its right size is raised).
  • yAccel: 0 when the phone is at rest on a flat surface, positive when its bottom is raised, and negative when its top is raised.
  • zAccel: Equal to -9.8 (earth's gravity in meters per second per second when the device is at rest parallel to the ground with the display facing up, 0 when perpendicular to the ground, and +9.8 when facing down. The value can also be affected by accelerating it with or against gravity.


Properties

You can set the below properties in the UI part of the builder.

  • Enabled - it's a boolean value which is set to true by default.
  • LegacyMode - it's a boolean value which is set to false by default.
  • MinimumInterval - it's a non negative integer value which is set to 400 by default.
  • Sensitivity - it's a accelerometer sensitivity value which is set to 2 by default.

Block Properties

You can set the below blocks properties in the blocks section of the builder.

Available

Returns whether the accelerometer is available on the device.


Enabled

If true, the sensor will generate events. Otherwise, no events are generated even if the device is accelerated or shaken.


MinimumInterval

The minimum interval, in milliseconds, between phone shakes


Sensitivity

A number that encodes how sensitive the accelerometer is. The choices are: 1 = weak, 2 = moderate, 3 = strong.


XAccel

Returns the acceleration in the X-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.


YAccel

Returns the acceleration in the Y-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.


ZAccel

Returns the acceleration in the Z-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.



Events

You can set the below event blocks in the blocks section of the builder.

AccelerationChanged

Indicates the acceleration changed in the X, Y, and/or Z dimensions.

Shaking

Indicates the device started being shaken or continues to be shaken.