Read Accelerometer Data | AIUI | Rokid

Register reading and error events before calling start(). Call stop() when leaving the page so sampling does not continue in the background.

Read Accelerometer Data

Register reading and error events before calling start(). Call stop() when leaving the page so sampling does not continue in the background.

Complete the Example

Register reading and error events before calling start(). Call stop() when leaving the page so sampling does not continue in the background.

const sensor = new Accelerometer({ frequency: 60 });

sensor.addEventListener('reading', () => {
  console.log(sensor.x, sensor.y, sensor.z);
});

sensor.addEventListener('error', (event) => {
  console.error('Sensor error', event.error);
});

sensor.start();

See Accelerometer for on-device availability and sampling limits.