1# @system.sensor (Sensor) 2 3The **Sensor** module provides APIs for querying the sensor list, subscribing to or unsubscribing from sensor data, and executing control commands. 4 5The sensors are classified into the following categories based on their functions: motion, environment, orientation, light, body, and other categories (such as Hall effect sensors). Each category includes different sensor types. A sensor type may be a single hardware sensor or a composite of multiple hardware sensors. 6 7 8> **NOTE** 9> 10> - The APIs of this module are no longer maintained since API version 8. You are advised to use [`@ohos.sensor`](js-apis-sensor.md) instead. 11> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. 12> - This module requires hardware support and can only be debugged on real devices. 13 14 15## Modules to Import 16 17 18``` 19import sensor from '@system.sensor'; 20``` 21 22## sensor.subscribeAccelerometer 23 24 subscribeAccelerometer(options: subscribeAccelerometerOptions): void 25 26Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. 27 28**System capability**: SystemCapability.Sensors.Sensor 29 30**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) 31 32**Parameters** 33 34| Name | Type | Mandatory| Description | 35| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 36| options | [subscribeAccelerometerOptions](#subscribeaccelerometeroptions) | Yes | Type of data to return.| 37 38**Example** 39 40```js 41sensor.subscribeAccelerometer({ 42 interval: 'normal', 43 success: function(ret) { 44 console.log('X-axis data: ' + ret.x); 45 console.log('Y-axis data: ' + ret.y); 46 console.log('Z-axis data: ' + ret.z); 47 }, 48 fail: function(data, code) { 49 console.error('Subscription failed. Code: ' + code + '; Data: ' + data); 50 }, 51}); 52``` 53 54> **NOTE** 55> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 56 57## sensor.unsubscribeAccelerometer 58 59unsubscribeAccelerometer(): void 60 61Unsubscribes from data changes of the acceleration sensor. 62 63**System capability**: SystemCapability.Sensors.Sensor 64 65**Required permissions**: ohos.permission.ACCELEROMETER (a system permission) 66 67**Example** 68 69```js 70sensor.unsubscribeAccelerometer(); 71``` 72 73## sensor.subscribeCompass 74 75 subscribeCompass(options: SubscribeCompassOptions): void 76 77Subscribes to data changes of the compass sensor. If this API is called multiple times for the same application, the last call takes effect. 78 79**System capability**: SystemCapability.Sensors.Sensor 80 81**Parameters** 82 83| Name | Type | Mandatory| Description | 84| ------- | --------------------------------------------------- | ---- | -------------------------------- | 85| options | [SubscribeCompassOptions](#subscribecompassoptions) | Yes | Type of data to return.| 86 87**Example** 88 89```js 90sensor.subscribeCompass({ 91 success: function(ret) { 92 console.log('get data direction:' + ret.direction); 93 }, 94 fail: function(data, code) { 95 console.error('Subscription failed. Code: ' + code + '; Data: ' + data); 96 }, 97}); 98``` 99 100> **NOTE** 101> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 102 103## sensor.unsubscribeCompass 104 105unsubscribeCompass(): void 106 107Unsubscribes from data changes of the compass sensor. 108 109**System capability**: SystemCapability.Sensors.Sensor 110 111**Example** 112 113```js 114sensor.unsubscribeCompass(); 115``` 116 117## sensor.subscribeProximity 118 119 subscribeProximity(options: SubscribeProximityOptions): void 120 121Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect. 122 123**System capability**: SystemCapability.Sensors.Sensor 124 125**Parameters** 126 127| Name | Type | Mandatory| Description | 128| ------- | ------------------------------------------------------- | ---- | -------------------------------- | 129| options | [SubscribeProximityOptions](#subscribeproximityoptions) | Yes | Type of data to return.| 130 131**Example** 132 133```js 134sensor.subscribeProximity({ 135 success: function(ret) { 136 console.log('get data distance:' + ret.distance); 137 }, 138 fail: function(data, code) { 139 console.error('Subscription failed. Code: ' + code + '; Data: ' + data); 140 }, 141}); 142``` 143 144> **NOTE** 145> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 146 147## sensor.unsubscribeProximity 148 149unsubscribeProximity(): void 150 151Unsubscribes from data changes of the proximity sensor. 152 153**System capability**: SystemCapability.Sensors.Sensor 154 155**Example** 156 157```js 158sensor.unsubscribeProximity(); 159``` 160 161## sensor.subscribeLight 162 163 subscribeLight(options: SubscribeLightOptions): void 164 165Subscribes to data changes of the ambient light sensor. If this API is called multiple times, the last call takes effect. 166 167**System capability**: SystemCapability.Sensors.Sensor 168 169**Parameters** 170 171| Name | Type | Mandatory| Description | 172| ------- | ----------------------------------------------- | ---- | ---------------------------------- | 173| options | [SubscribeLightOptions](#subscribelightoptions) | Yes | Type of data to return.| 174 175**Example** 176 177```js 178sensor.subscribeLight({ 179 success: function(ret) { 180 console.log('get data intensity:' + ret.intensity); 181 }, 182 fail: function(data, code) { 183 console.error('Subscription failed. Code: ' + code + '; Data: ' + data); 184 }, 185}); 186``` 187 188> **NOTE** 189> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 190 191## sensor.unsubscribeLight 192 193unsubscribeLight(): void 194 195Unsubscribes from data changes of the ambient light sensor. 196 197**System capability**: SystemCapability.Sensors.Sensor 198 199**Example** 200 201```js 202sensor.unsubscribeLight(); 203``` 204 205## sensor.subscribeStepCounter 206 207 subscribeStepCounter(options: SubscribeStepCounterOptions): void 208 209Subscribes to data changes of the step counter sensor. If this API is called multiple times for the same application, the last call takes effect. 210 211**System capability**: SystemCapability.Sensors.Sensor 212 213**Required permissions**: ohos.permission.ACTIVITY_MOTION 214 215**Parameters** 216 217| Name | Type | Mandatory| Description | 218| ------- | ----------------------------------------------------------- | ---- | -------------------------------------- | 219| options | [SubscribeStepCounterOptions](#subscribestepcounteroptions) | Yes | Type of data to return.| 220 221**Example** 222 223```js 224sensor.subscribeStepCounter({ 225 success: function(ret) { 226 console.log('get step value:' + ret.steps); 227 }, 228 fail: function(data, code) { 229 console.log('Subscription failed. Code: ' + code + '; Data: ' + data); 230 }, 231}); 232``` 233 234> **NOTE** 235> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 236 237## sensor.unsubscribeStepCounter 238 239unsubscribeStepCounter(): void 240 241Unsubscribes from data changes of the step counter sensor. 242 243**System capability**: SystemCapability.Sensors.Sensor 244 245**Required permissions**: ohos.permission.ACTIVITY_MOTION 246 247**Example** 248 249```js 250sensor.unsubscribeStepCounter(); 251``` 252 253 254## sensor.subscribeBarometer 255 256subscribeBarometer(options: SubscribeBarometerOptions): void 257 258Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect. 259 260**System capability**: SystemCapability.Sensors.Sensor 261 262**Parameters** 263 264| Name | Type | Mandatory| Description | 265| ------- | ------------------------------------------------------- | ---- | ---------------------------------- | 266| options | [SubscribeBarometerOptions](#subscribebarometeroptions) | Yes | Type of data to return.| 267 268**Example** 269 270```js 271sensor.subscribeBarometer({ 272 success: function(ret) { 273 console.log('get data value:' + ret.pressure); 274 }, 275 fail: function(data, code) { 276 console.log('Subscription failed. Code: ' + code + '; Data: ' + data); 277 }, 278}); 279``` 280 281> **NOTE** 282> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 283 284 285## sensor.unsubscribeBarometer 286 287unsubscribeBarometer(): void 288 289Unsubscribes from data changes of the barometer sensor. 290 291**System capability**: SystemCapability.Sensors.Sensor 292 293**Example** 294 295```js 296sensor.unsubscribeBarometer(); 297``` 298 299 300## sensor.subscribeHeartRate 301 302 subscribeHeartRate(options: SubscribeHeartRateOptions): void 303 304Subscribes to data changes of the heart rate sensor. If this API is called multiple times for the same application, the last call takes effect. 305 306**System capability**: SystemCapability.Sensors.Sensor 307 308**Required permissions**: ohos.permission.READ_HEALTH_DATA 309 310**Parameters** 311 312| Name | Type | Mandatory| Description | 313| ------- | ------------------------------------------------------- | ---- | -------------------------------- | 314| options | [SubscribeHeartRateOptions](#subscribeheartrateoptions) | Yes | Type of data to return.| 315 316**Example** 317 318```js 319sensor.subscribeHeartRate({ 320 success: function(ret) { 321 console.log('get heartrate value:' + ret.heartRate); 322 }, 323 fail: function(data, code) { 324 console.log('Subscription failed. Code: ' + code + '; Data: ' + data); 325 }, 326}); 327``` 328 329> **NOTE** 330> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 331 332 333## sensor.unsubscribeHeartRate 334 335unsubscribeHeartRate(): void 336 337Unsubscribes from data changes of the heart rate sensor. 338 339**System capability**: SystemCapability.Sensors.Sensor 340 341**Required permissions**: ohos.permission.READ_HEALTH_DATA 342 343**Example** 344 345```js 346sensor.unsubscribeHeartRate(); 347``` 348 349## sensor.subscribeOnBodyState 350 351 subscribeOnBodyState(options: SubscribeOnBodyStateOptions): void 352 353Subscribes to changes of the wearing state of a wearable device. If this API is called multiple times for the same application, the last call takes effect. 354 355**System capability**: SystemCapability.Sensors.Sensor 356 357**Parameters** 358 359| Name | Type | Mandatory| Description | 360| ------- | ----------------------------------------------------------- | ---- | ---------------------- | 361| options | [SubscribeOnBodyStateOptions](#subscribeonbodystateoptions) | Yes | Type of data to return.| 362 363**Example** 364 365```js 366sensor.subscribeOnBodyState({ 367 success: function(ret) { 368 console.log('get on-body state value:' + ret.value); 369 }, 370 fail: function(data, code) { 371 console.log('Subscription failed. Code: ' + code + '; Data: ' + data); 372 }, 373}); 374``` 375 376> **NOTE** 377> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 378 379## sensor.unsubscribeOnBodyState 380 381unsubscribeOnBodyState(): void 382 383Unsubscribes from changes of the wearing state of a wearable device. 384 385**System capability**: SystemCapability.Sensors.Sensor 386 387**Example** 388 389```js 390sensor.unsubscribeOnBodyState(); 391``` 392 393## sensor.getOnBodyState 394 395 getOnBodyState(options: GetOnBodyStateOptions): void 396 397Obtains the wearing state of a wearable device. 398 399**System capability**: SystemCapability.Sensors.Sensor 400 401**Parameters** 402 403| Name | Type | Mandatory| Description | 404| ------- | ----------------------------------------------- | ---- | -------------------------- | 405| options | [GetOnBodyStateOptions](#getonbodystateoptions) | Yes | Type of data to return.| 406 407**Example** 408 409```js 410sensor.getOnBodyState({ 411 success: function(ret) { 412 console.log('on body state: ' + ret.value); 413 }, 414 fail: function(data, code) { 415 console.log('Subscription failed. Code: ' + code + '; Data: ' + data); 416 }, 417}); 418``` 419 420## sensor.subscribeDeviceOrientation<sup>6+</sup> 421 422 subscribeDeviceOrientation(options: SubscribeDeviceOrientationOptions): void 423 424Subscribes to data changes of the device orientation sensor. 425 426If this API is called multiple times for the same application, the last call takes effect. However, this API cannot be called multiple times in one click event. 427 428**System capability**: SystemCapability.Sensors.Sensor 429 430**Parameters** 431 432| Name | Type | Mandatory| Description | 433| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ | 434| options | [SubscribeDeviceOrientationOptions](#subscribedeviceorientationoptions) | Yes | Type of data to return.| 435 436**Example** 437 438```js 439sensor.subscribeDeviceOrientation({ 440 interval: 'normal', 441 success: function(ret) { 442 console.log('Alpha data: ' + ret.alpha); 443 console.log('Beta data: ' + ret.beta); 444 console.log('Gamma data: ' + ret.gamma); 445 }, 446 fail: function(data, code) { 447 console.error('Subscription failed. Code: ' + code + '; Data: ' + data); 448 } 449}); 450``` 451 452> **NOTE** 453> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 454 455## sensor.unsubscribeDeviceOrientation<sup>6+</sup> 456 457unsubscribeDeviceOrientation(): void 458 459Unsubscribes from data changes of the device orientation sensor. 460 461**System capability**: SystemCapability.Sensors.Sensor 462 463**Example** 464 465```js 466sensor.unsubscribeDeviceOrientation(); 467``` 468 469## sensor.subscribeGyroscope<sup>6+</sup> 470 471 subscribeGyroscope(options: SubscribeGyroscopeOptions): void 472 473Subscribes to data changes of the gyroscope sensor. 474 475If this API is called multiple times for the same application, the last call takes effect. However, this API cannot be called multiple times in one click event. 476 477**System capability**: SystemCapability.Sensors.Sensor 478 479**Required permissions**: ohos.permission.GYROSCOPE (a system permission) 480 481**Parameters** 482 483| Name | Type | Mandatory| Description | 484| ------- | ------------------------------------------------------- | ---- | ---------------------------------------------- | 485| options | [SubscribeGyroscopeOptions](#subscribegyroscopeoptions) | Yes | Type of data to return.| 486 487**Example** 488 489```js 490sensor.subscribeGyroscope({ 491 interval: 'normal', 492 success: function(ret) { 493 console.log('X-axis data: ' + ret.x); 494 console.log('Y-axis data: ' + ret.y); 495 console.log('Z-axis data: ' + ret.z); 496 }, 497 fail: function(data, code) { 498 console.error('Subscription failed. Code: ' + code + '; data: ' + data); 499 } 500}); 501``` 502 503> **NOTE** 504> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestory** callback. 505 506## sensor.unsubscribeGyroscope<sup>6+</sup> 507 508unsubscribeGyroscope(): void 509 510Unsubscribes from data changes of the gyroscope sensor. 511 512**System capability**: SystemCapability.Sensors.Sensor 513 514**Required permissions**: ohos.permission.GYROSCOPE (a system permission) 515 516**Example** 517 518```js 519sensor.unsubscribeGyroscope(); 520``` 521 522## subscribeAccelerometerOptions 523 524Defines the type of data to return for a subscription to the acceleration sensor data. 525 526**Required permissions**: ohos.permission.ACCELEROMETER 527 528**System capability**: SystemCapability.Sensors.Sensor 529 530| Name | Type | Mandatory| Description | 531| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 532| interval | string | Yes | Execution frequency of the callback for returning the acceleration sensor data. The default value is **normal**. The options are as follows: - **game**: called at an interval of 20 ms, which is applicable to gaming scenarios. - **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios. - **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| 533| success | [AccelerometerResponse](#accelerometerresponse) | Yes | Called when the acceleration sensor data changes. | 534| fail | Function | No | Callback upon an API call failure. | 535 536## AccelerometerResponse 537 538Defines the type of data to include in an **AccelerometerResponse** object. 539 540**Required permissions**: ohos.permission.ACCELEROMETER 541 542**System capability**: SystemCapability.Sensors.Sensor 543 544| Name| Type | Mandatory| Description | 545| ---- | ------ | ---- | ------------- | 546| x | number | Yes | Acceleration on the x-axis.| 547| y | number | Yes | Acceleration on the y-axis.| 548| z | number | Yes | Acceleration on the z-axis.| 549 550## SubscribeCompassOptions 551 552Defines the type of data to return for a subscription to the compass sensor data. 553 554**System capability**: SystemCapability.Sensors.Sensor 555 556| Name | Type | Mandatory| Description | 557| ------- | ----------------------------------- | ---- | ------------------------------ | 558| success | [CompassResponse](#compassresponse) | Yes | Called when the compass sensor data changes.| 559| fail | Function | No | Callback upon an API call failure. | 560 561## CompassResponse 562 563Defines the type of data to include in a **CompassResponse** object. 564 565**System capability**: SystemCapability.Sensors.Sensor 566 567| Name | Type | Mandatory| Description | 568| --------- | ------ | ---- | -------------------- | 569| direction | number | Yes | Direction of the device, in degrees.| 570 571## SubscribeProximityOptions 572 573Defines the type of data to return for a subscription to the proximity sensor data. 574 575**System capability**: SystemCapability.Sensors.Sensor 576 577| Name | Type | Mandatory| Description | 578| ------- | --------------------------------------- | ---- | ---------------------------------- | 579| success | [ProximityResponse](#proximityresponse) | Yes | Called when the proximity sensor data changes.| 580| fail | Function | No | Callback upon an API call failure. | 581 582## ProximityResponse 583 584Defines the type of data to include in a **ProximityResponse** object. 585 586**System capability**: SystemCapability.Sensors.Sensor 587 588| Name | Type | Mandatory| Description | 589| -------- | ------ | ---- | ------------------------------------------ | 590| distance | number | Yes | Distance between a visible object and the device screen.| 591 592## SubscribeLightOptions 593 594Defines the type of data to return for a subscription to the ambient light sensor data. 595 596**System capability**: SystemCapability.Sensors.Sensor 597 598| Name | Type | Mandatory| Description | 599| ------- | ------------------------------- | ---- | ------------------------------ | 600| success | [LightResponse](#lightresponse) | Yes | Called when the ambient light sensor data changes| 601| fail | Function | No | Callback upon an API call failure. | 602 603## LightResponse 604 605Defines the type of data to include in a **LightResponse** object. 606 607**System capability**: SystemCapability.Sensors.Sensor 608 609| Name | Type | Mandatory| Description | 610| --------- | ------ | ---- | --------------------- | 611| intensity | number | Yes | Light intensity, in lux.| 612 613## SubscribeStepCounterOptions 614 615Defines the type of data to return for a subscription to the step counter sensor data. 616 617**Required permissions**: ohos.permission.ACTIVITY_MOTION 618 619**System capability**: SystemCapability.Sensors.Sensor 620 621| Name | Type | Mandatory| Description | 622| ------- | ------------------------------------------- | ---- | -------------------------------- | 623| success | [StepCounterResponse](#stepcounterresponse) | Yes | Called when the step counter sensor data changes.| 624| fail | Function | No | Callback upon an API call failure. | 625 626## StepCounterResponse 627 628Defines the type of data to include in a **StepCounterResponse** object. 629 630**Required permissions**: ohos.permission.ACTIVITY_MOTION 631 632**System capability**: SystemCapability.Sensors.Sensor 633 634| Name | Type | Mandatory| Description | 635| ----- | ------ | ---- | -------------------------------- | 636| steps | number | Yes | Number of counted steps after the sensor is restarted.| 637 638## SubscribeBarometerOptions 639 640Defines the type of data to return for a subscription to the barometer sensor data. 641 642**System capability**: SystemCapability.Sensors.Sensor 643 644| Name | Type | Mandatory| Description | 645| ------- | --------------------------------------- | ---- | -------------------------------- | 646| success | [BarometerResponse](#barometerresponse) | Yes | Called when the barometer sensor data changes.| 647| fail | Function | No | Callback upon an API call failure. | 648 649## BarometerResponse 650 651Defines the type of data to include in a **BarometerResponse** object. 652 653**System capability**: SystemCapability.Sensors.Sensor 654 655| Name | Type | Mandatory| Description | 656| -------- | ------ | ---- | ---------------------- | 657| pressure | number | Yes | Pressure, in pascal.| 658 659## SubscribeHeartRateOptions 660 661Defines the type of data to return for a subscription to the heart rate sensor data. 662 663**Required permissions**: ohos.permission.READ_HEALTH_DATA 664 665**System capability**: SystemCapability.Sensors.Sensor 666 667| Name | Type | Mandatory| Description | 668| ------- | --------------------------------------- | ---- | ----------------------------------------------- | 669| success | [HeartRateResponse](#heartrateresponse) | Yes | Called when the heart rate sensor data changes. This callback is invoked every five seconds.| 670| fail | Function | No | Callback upon an API call failure. | 671 672## HeartRateResponse 673 674Defines the type of data to include in a **HeartRateResponse** object. 675 676**Required permissions**: ohos.permission.READ_HEALTH_DATA 677 678**System capability**: SystemCapability.Sensors.Sensor 679 680| Name | Type | Mandatory| Description | 681| --------- | ------ | ---- | -------- | 682| heartRate | number | Yes | Heart rate.| 683 684## SubscribeOnBodyStateOptions 685 686Defines the type of data to return for a subscription to the wearing state changes. 687 688**System capability**: SystemCapability.Sensors.Sensor 689 690| Name | Type | Mandatory| Description | 691| ------- | ------------------------------------------- | ---- | -------------------------- | 692| success | [OnBodyStateResponse](#onbodystateresponse) | Yes | Called when the wearing state changes.| 693| fail | Function | No | Callback upon an API call failure. | 694 695## OnBodyStateResponse 696 697Defines the wearing state. 698 699**System capability**: SystemCapability.Sensors.Sensor 700 701| Name | Type | Mandatory| Description | 702| ----- | ------- | ---- | ------------ | 703| value | boolean | Yes | Whether the wearable device is worn.| 704 705## GetOnBodyStateOptions 706 707 Defines the type of data to return for obtaining the wearing state. 708 709**System capability**: SystemCapability.Sensors.Sensor 710 711| Name | Type | Mandatory| Description | 712| -------- | ------------------------------------------- | ---- | ------------------------ | 713| success | [OnBodyStateResponse](#onbodystateresponse) | No | Callback upon a successful API call.| 714| fail | Function | No | Callback upon an API call failure.| 715| complete | Function | No | Called when the API call is complete.| 716 717## SubscribeDeviceOrientationOptions<sup>6+</sup> 718 719Defines the type of data to return for a subscription to the device orientation sensor data. 720 721**System capability**: SystemCapability.Sensors.Sensor 722 723| Name | Type | Mandatory| Description | 724| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 725| interval | string | Yes | Interval at which the callback is invoked to return the device orientation sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| 726| success | [DeviceOrientationResponse](#deviceorientationresponse) | Yes | Called when the device orientation sensor data changes. | 727| fail | Function | No | Callback upon an API call failure. | 728 729## DeviceOrientationResponse<sup>6+</sup> 730 731Defines the type of data to include in a **DeviceOrientationResponse** object. 732 733**System capability**: SystemCapability.Sensors.Sensor 734 735| Name | Type | Mandatory| Description | 736| ----- | ------ | ---- | ------------------------------------------------------------ | 737| alpha | number | Yes | Rotation angle around the Z axis when the X/Y axis of the device coincides with the X/Y axis of the earth.| 738| beta | number | Yes | Rotation angle around the X axis when the Y/Z axis of the device coincides with the Y/Z axis of the earth.| 739| gamma | number | Yes | Rotation angle around the Y axis when the X/Z axis of the device coincides with the X/Z axis of the earth.| 740 741## SubscribeGyroscopeOptions<sup>6+</sup> 742 743Defines the type of data to return for a subscription to the gyroscope sensor data. 744 745**Required permissions**: ohos.permission.GYROSCOPE 746 747**System capability**: SystemCapability.Sensors.Sensor 748 749| Name | Type | Mandatory| Description | 750| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 751| interval | string | Yes | Interval at which the callback is invoked to return the gyroscope sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| 752| success | [GyroscopeResponse](#gyroscoperesponse) | Yes | Called when the gyroscope sensor data changes. | 753| fail | Function | No | Callback upon an API call failure. | 754 755## GyroscopeResponse<sup>6+</sup> 756 757Defines the type of data to include in a **GyroscopeResponse** object. 758 759**Required permissions**: ohos.permission.GYROSCOPE 760 761**System capability**: SystemCapability.Sensors.Sensor 762 763| Name| Type | Mandatory| Description | 764| ---- | ------ | ---- | ----------------- | 765| x | number | Yes | Rotation angular velocity of the X axis.| 766| y | number | Yes | Rotation angular velocity of the Y axis.| 767| z | number | Yes | Rotation angular velocity of the Z axis.| 768