Skip to content

Magnetometer Sensor

The Magnetometer sensor class provides access to a three-dimensional magnetometer.

Creates a new Magnetometer object instance.

Magnetometer(options)

options

An object of properties used to construct the class.

sensor - The hardware connection definition.

interval (optional) - The sampling interval in milliseconds.

Returns a sample object containing the current magnetic field data.

sample()

An object with the following properties:

x - A number that represents the sampled magnetic field around the x axis in microtesla.

y - A number that represents the sampled magnetic field around the y axis in microtesla.

z - A number that represents the sampled magnetic field around the z axis in microtesla.

const sensor = new device.sensor.Magnetometer({
sensor: {
io: device.io.I2C,
address: 0x1E
}
});
const sample = sensor.sample();
console.log(`X: ${sample.x} uT, Y: ${sample.y} uT, Z: ${sample.z} uT`);

Magnetometer