files/en-us/web/api/sensor/reading_event/index.md
{{securecontext_header}}{{APIRef("Sensor API")}}
The reading event is fired when a new reading is available on a sensor.
The {{domxref('Sensor')}} interface is a base class, onreading and the reading event may only be used
on one of the derived classes.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("reading", (event) => { })
onreading = (event) => { }
A generic {{domxref("Event")}} with no added properties.
This example adds an event listener to read acceleration values of an {{domxref("Accelerometer")}}. It reads sixty times a second.
const acl = new Accelerometer({ frequency: 60 });
acl.addEventListener("reading", () => {
console.log(`Acceleration along the X-axis ${acl.x}`);
console.log(`Acceleration along the Y-axis ${acl.y}`);
console.log(`Acceleration along the Z-axis ${acl.z}`);
});
acl.start();
{{Specifications}}
{{Compat}}