1# Sensor Usage Guidelines 2 3The following steps use the sensor whose **sensorTypeId** is **0** as an example. The guidelines for other sensor types are similar. 4 5## How to Use 6 71. Import the required header files. 8 9 10 ```c 11 #include "sensor_agent.h" 12 #include "sensor_agent_type.h" 13 ``` 14 152. Create a sensor callback. 16 17 ```c 18 void SensorDataCallbackImpl(SensorEvent *event) 19 { 20 if(event == NULL){ 21 return; 22 } 23 float *sensorData=(float *)event->data; 24 } 25 ``` 26 27 > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** 28 > The callback must be of the RecordSensorCallback type. 29 303. Obtain the list of sensors supported by the device. 31 32 ```c 33 SensorInfo *sensorInfo = (SensorInfo *)NULL; 34 int32_t count = 0; 35 int32_t ret = GetAllSensors(&sensorInfo, &count); 36 ``` 37 384. Create a sensor user. 39 40 ```c 41 SensorUser sensorUser; 42 sensorUser.callback = SensorDataCallbackImpl; // Assign the created callback SensorDataCallbackImpl to the member variable callback. 43 ``` 44 455. Enable the sensor. 46 47 ```c 48 int32_t ret = ActivateSensor(0, &sensorUser); 49 ``` 50 516. Subscribe to sensor data. 52 53 ```c 54 int32_t ret = SubscribeSensor(0, &sensorUser); 55 ``` 56 57 > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** 58 > Till now, you can obtain the sensor data via the callback. 59 607. Unsubscribe from the sensor data. 61 62 ```c 63 int32_t ret = UnsubscribeSensor(0, &sensorUser); 64 ``` 65 668. Disable the sensor. 67 68 ```c 69 int32_t ret = DeactivateSensor(0, &sensorUser); 70 ``` 71