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

##

## Adding a Magnetometer to your app

To add a Magnetometer to your app:

1. Navigate to the **Blocks** tab of your project.
2. Under the App Features heading, locate **Sensors**.&#x20;
3. Click the ⊕ symbol next to Sensor.
4. Select **Magnetometer** from the provided menu.
5. Click **Add**.

![](/files/-MMGscus1Tmzgj_p_Z1B)

![](/files/-MMGtN30eJmSdWNKCxqJ)

You will see a settings panel where you can set:

* The **Name** of the Magnetometer
* Whether the Magnetometer is **Enabled**

You can either confirm your choices and create the Magnetometer, or delete the Magnetometer.

![](/files/-MJXErvpfdNuZXEXBlFp)

### Change Settings of Magnetometer <a href="#change-settings-of-magnetometer" id="change-settings-of-magnetometer"></a>

‌You will see the sensors you have added to your app underneath the Sensors section of your blocks.

![](/files/-MMGtPseGdJ7VyPZ-cB9)

\
If you click on the ⚙ icon next to your Magnetometer, you will be able to edit its settings as seen in the panels above. You can click on your Magnetometer's name to access its drawer of blocks.‌

## Properties

| Property | Description                                             | Data Type  |
| -------- | ------------------------------------------------------- | ---------- |
| Enabled  | Toggle whether the component is functioning in your app | True/False |

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

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


---

# 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/blocks/app-features/sensors-blocks/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.
