# 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.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-LfAKkxNBiTf9-hUVp0f%2F-LfAKq11ubZzw9kwMlpm%2FScreenshot%202019-05-18%20at%2015.27.06.png?alt=media\&token=022db7f3-8781-4e58-b93f-aa810c0b5937)

‌

## 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;

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-LfA1BsyDXYWwu4FI79m%2F-LfA4bX6k2xqUUzGmwaC%2FScreenshot%202019-05-18%20at%2014.15.20.png?alt=media\&token=0a24d7f3-c7bf-4a30-a0fb-870956cf8ba6)

| 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

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJXHtjROd9cUX4YXQuV%2F-MJXIB7xEnujMdM2zIOL%2Fimage.png?alt=media\&token=fb0c225c-b6f0-4d63-a8e5-0ef7e408b51b)

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

#### Call Y

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJXHtjROd9cUX4YXQuV%2F-MJXICdUVCB-3PQGjfgE%2Fimage.png?alt=media\&token=dcd4d828-f1ee-4933-a472-5c1deac72c08)

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

#### Call Z

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJXHtjROd9cUX4YXQuV%2F-MJXIFrWwhxO5_V4eaoa%2Fimage.png?alt=media\&token=9607a8cd-d858-46a0-a5d3-e14813cd78f5)

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

#### Call Heading

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJXHtjROd9cUX4YXQuV%2F-MJXIHiFRnXML4CUyWqx%2Fimage.png?alt=media\&token=ea54863a-e732-4939-8479-cfcb622784f9)

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.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXHM010I_0QovWUcLfk%2F-MXHOvo-WvJCMk0vee9T%2Fmag_enabled.png?alt=media\&token=bb72906d-8843-4c60-84fc-f9ee1b2c5008)

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.thunkable.com/snap-to-place/magnetometer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
