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