> For the complete documentation index, see [llms.txt](https://docs.thunkable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.thunkable.com/snap-to-place/magnetometer.md).

# Magnetometer

## Description

The magnetometer is used to measure magnetic flux density. This is the total magnetic field passing through a given area, per metre squared, $$\frac{T \cdot m^2}{m^2}$$ . The sensor will returns values with units of microtesla $$\mu T$$ for each of the three coordinate axes; x, y and, z. The magnetic flux density is quite similar to magnetic field strength.

![](/files/-LfAKq11ubZzw9kwMlpm)

‌

## Blocks

### Events

#### When Magnetometer Changes

When the magnetometer detects a change in the ambient magnetic field the `Changes` event will fire. The event returns 4 parameters that we can work with.&#x20;

![](/files/-LfA4bX6k2xqUUzGmwaC)

| Parameter      | Type   | Returns                                                  |
| -------------- | ------ | -------------------------------------------------------- |
| `xFluxDensity` | Number | Flux density, in the x direction, expressed in $$\mu T$$ |
| `yFluxDensity` | Number | Flux density, in the y direction, expressed in $$\mu T$$ |
| `zFluxDensity` | Number | Flux density, in the z direction, expressed in $$\mu T$$ |
| `error`        | String | Error message from the Sensor                            |

### Functions

#### Call X

![](/files/-MJXIB7xEnujMdM2zIOL)

Returns flux density, in the x direction, expressed in $$\mu T$$

#### Call Y

![](/files/-MJXICdUVCB-3PQGjfgE)

Returns flux density, in the y  direction, expressed in $$\mu T$$

#### Call Z

![](/files/-MJXIFrWwhxO5_V4eaoa)

Returns flux density, in the x direction, expressed in $$\mu T$$

#### Call Heading

![](/files/-MJXIHiFRnXML4CUyWqx)

Returns a value between 0 and 360 which denotes the user's direction relative to the Earth's geographic North Pole

### Properties

#### Enabled

The magnetometer is, by default, turned on, but the `enabled` property can be used to turn in on and off by setting it to `true` or `false` respectively.

![](/files/-MXHOvo-WvJCMk0vee9T)

| Property      | Type | Default |
| ------------- | ---- | ------- |
| `set Enabled` | Bool | true    |
| `get Enabled` | Bool | true    |
