1# Sensor Development 2 3 4## When to Use 5 6With the sensor module, a device can obtain sensor data. For example, the device can subscribe to data of the orientation sensor to detect its own orientation. 7 8For details about the APIs, see [Sensor](../../reference/apis-sensor-service-kit/js-apis-sensor.md). 9 10 11## Available APIs 12 13| Name| Description| 14| -------- | -------- | 15| sensor.on(sensorId, callback:AsyncCallback<Response>): void | Subscribes to data changes of a type of sensor.| 16| sensor.off(sensorId, callback?:AsyncCallback<void>): void | Unsubscribes from sensor data changes.| 17 18 19## How to Develop 20 21The acceleration sensor is used as an example. 22 231. Import modules. 24 25 ```ts 26 import { sensor } from '@kit.SensorServiceKit'; 27 ``` 28 292. Check whether the corresponding permission has been configured. For details, see [Declaring Permissions](../../security/AccessToken/declare-permissions.md). 30 313. Register a listener. 32 33 The **on()** API is used to continuously listen for data changes of the sensor. The sensor reporting interval is set to **game**. 34 35 ```ts 36 sensor.on(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { 37 console.info("Succeeded in obtaining data. x: " + data.x + " y: " + data.y + " z: " + data.z); 38 }, { interval: 'game' }); 39 ``` 40 41  42 434. Cancel continuous listening. 44 45 ```ts 46 sensor.off(sensor.SensorId.ACCELEROMETER); 47 ``` 48