# Adafruit TLV493 Triple-Axis Magnetometer

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/080/820/medium800thumb/sensors_mag_wiggle_larger.jpg?1568232970)

The TLV493D 3-axis magnetometer is a great little sensor for detecting magnets[_ **in 3D** _.](https://www.youtube.com/watch?v=3FQDUX6X6-w) In fact, the manufacturer Infineon suggests it could be used to make a joystick! You could also use it for other cool things like detecting objects with magnets attached, like the lid of a box, or maybe a statue that unlocks your secret lair when placed on your mantle?

The TLD493D excels at measuring nearby magnetic fields in three dimensions. It's not going to make a good compass, it's not sensitive enough to pick up the Earth's magnetic field, but you can use it to track the movement of nearby magnets in three dimensions.&nbsp;

Here are a few specs:

- Digital output via 2-wire based standard I2C interface up to 1 MBit/sec
- 12-bit data resolution for each measurement direction
- Bx, By and Bz linear field measurement up to +130 [mT](https://en.wikipedia.org/wiki/Tesla_(unit))
- Excellent matching of X/Y measurement for accurate angle sensing

![](https://cdn-learn.adafruit.com/assets/assets/000/080/757/medium800/sensors_4366_quarter_orig_2019_09.jpg?1568143130)

As we are wont to do, we've made the TLV easy to use by putting it on a breakout PCB along with the circuitry to support it. A voltage regulator and logic level shifting combine to make it usable with a range of microcontrollers with either 3.3V or 5V logic levels. We even give you a pin for you to use the excess 3.3V juice not needed by the TLV493D.

![](https://cdn-learn.adafruit.com/assets/assets/000/080/756/medium800/sensors_4366_iso_orig_2019_09.jpg?1568143051)

We've also outfitted the breakout with&nbsp;[SparkFun Qwiic](https://www.sparkfun.com/qwiic) compatible [**STEMMA QT**](https://learn.adafruit.com/introducing-adafruit-stemma-qt) connectors to allow you to use it with other similarly equipped boards **without needing to solder.** &nbsp;Because the TLV394D "speaks" I2C, you only need two wires (in addition to power) to interface with your microcontroller, and you can share those pins with other I2C sensors. The manufacturer Infineon was kind enough to provide a library to use the sensor with Arduino, and we've written one to use it with CircuitPython.

Read on and you'll be sensing magnets with 12-bit precision in no time!

# Adafruit TLV493 Triple-Axis Magnetometer

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/080/758/medium800/sensors_cover_image.jpg?1568143540)

# Power Pins

- **Vin** - this is the power pin. Since the sensor chip uses 3.3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V
- **3Vo** - this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like
- **GND** - common ground for power and logic

## I2C Logic Pins

- **SCL** - this is the I2C clock pin, connect to your microcontroller's I2C clock line.
- **SDA** - this is the I2C data pin, connect to your microcontroller's I2C data line
- **[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)&nbsp;-** These connectors allow you to connectors to dev boards with&nbsp; **STEMMA QT** connectors or to other things with&nbsp;[various associated accessories](https://www.adafruit.com/?q=JST%20SH%204)

# Adafruit TLV493 Triple-Axis Magnetometer

## Arduino

# I2C Wiring
Wiring the TLV493D is easy, since it only requires power and two wires for an I2C connection. Additionally, the STEMMA QT connectors give you additional solderless options for wiring:

- &nbsp;Connect&nbsp;**board VCC (red wire)** to&nbsp; **Arduino**  **5V** &nbsp;if you are running a **5V** board Arduino (Uno, etc.).&nbsp;If your board is **3V,** connect to that instead.
- Connect **board** **GND (black wire)&nbsp;**to&nbsp; **Arduino**  **GND**
- Connect **board** **SCL (yellow wire)&nbsp;**to&nbsp; **Arduino**  **SCL**
- Connect **board** **SDA (blue wire)&nbsp;**to&nbsp; **Arduino**  **SDA**

![sensors_arduino_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/080/442/medium640/sensors_arduino_wiring.png?1567618578)

![sensors_arduino_breadboard.png](https://cdn-learn.adafruit.com/assets/assets/000/080/446/medium640/sensors_arduino_breadboard.png?1567619575)

# Arduino Library Installation

Fortunately Infineon have written a library for you for the TLV493D which you can install using the Arduino IDE's **Library Manager** :

Click the&nbsp; **Manage Libraries ...** &nbsp;menu item, search for&nbsp; **Xensiv TLx493D** and install it. Make sure to avoid the deprecated versions that might appear with similar names.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/133/859/medium800/sensors_Screenshot_2024-11-30_at_7.56.55_AM.png?1732984656)

![](https://cdn-learn.adafruit.com/assets/assets/000/133/863/medium800/sensors_Screenshot_2024-11-30_at_7.59.20_AM.png?1732984767)

# Xensiv / Infineon Examples

There are a few examples, but which read the X, Y, and Z axis measurements in [milli-teslas (**mT)**](https://en.wikipedia.org/wiki/Tesla_(unit)).

You can see the examples by navigating to the appropriate spot in the File --\> Examples --\> XENSIV 3D submenu. To get started quickly here is a simple variation on the read\_iic\_sensor.

Info: Many Adafruit boards have two I2C buses. You might need to change Wire to Wire1. 

![](https://cdn-learn.adafruit.com/assets/assets/000/133/864/medium800/sensors_Screenshot_2024-11-30_at_8.28.52_AM.png?1732985067)

The code below is the example **read\_iic\_sensor** from the Arduino IDE Examples -\> XENSIV 3D Magnetic Sensor TLx493D. The examples are available after you load the library as shown above.

```auto
/** Project CPP includes. */
#include "TLx493D_inc.hpp"


using namespace ifx::tlx493d;


/* Definition of the power pin and sensor objects for Kit2Go XMC1100 boards. */
// const uint8_t POWER_PIN = 15; // XMC1100 : LED2

// TLx493D_A1B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);

// TLx493D_A2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_P2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);


/** Definition of the power pin and sensor objects for S2Go with XMC4700 Relax Lite board. */
// const uint8_t POWER_PIN = 8; // XMC : P1.10

// TLx493D_A1B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);

// TLx493D_A2BW dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2BW dut(Wire, TLx493D_IIC_ADDR_A0_e);


/** P3XX evaluation board */
const uint8_t POWER_PIN = 8;
TLx493D_P3B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);


/** Definition of the power pin and sensor objects for Arduino Uno boards */
/** Care must be taken to level shift down to 3.3V as the sensor boards expect only 3.3V ! */
/** Therefore disabled here. */
// const uint8_t POWER_PIN = 7;

// TLx493D_W2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2BW dut(Wire, TLx493D_IIC_ADDR_A0_e);


/** Definition of a counter variable. */
uint8_t count = 0;


void setup() {
    Serial.begin(115200);
    delay(3000);

    /** Definition of the power pin to power up the sensor. */
    /** Set delay after power-on to 50 for A1B6 Kit2Go sensor. */
    /** All other Kit2Go boards */
    // dut.setPowerPin(POWER_PIN, OUTPUT, INPUT, HIGH, LOW, 0, 250000);

    /** P3XX evaluation board */
    dut.setPowerPin(POWER_PIN, OUTPUT, INPUT, LOW, HIGH, 1000, 250000);

    dut.begin();

    Serial.print("setup done.\n");
}


/** In the loop we continuously reading the temperature value as well as the
 *  magnetic values in X, Y, Z-direction of the sensor and printing them to
 *  the serial monitor
 */
void loop() {
    double t, x, y, z;

    dut.setSensitivity(TLx493D_FULL_RANGE_e);
    Serial.print(true == dut.getMagneticFieldAndTemperature(&amp;x, &amp;y, &amp;z, &amp;t) ? "getMagneticFieldAndTemperature ok\n" : "getMagneticFieldAndTemperature error\n");

    dut.printRegisters();

    Serial.print("\nTemperature is: ");
    Serial.print(t);
    Serial.println("°C");

    Serial.print("Value X is: ");
    Serial.print(x);
    Serial.println(" mT");
    Serial.print("Value Y is: ");
    Serial.print(y);
    Serial.println(" mT");
    Serial.print("Value Z is: ");
    Serial.print(z);
    Serial.println(" mT");

    dut.setSensitivity(TLx493D_SHORT_RANGE_e);
    Serial.print(true == dut.getMagneticFieldAndTemperature(&amp;x, &amp;y, &amp;z, &amp;t) ? "getMagneticFieldAndTemperature ok\n" : "getMagneticFieldAndTemperature error\n");

    dut.printRegisters();

    Serial.print("\nTemperature is: ");
    Serial.print(t);
    Serial.println("°C");

    Serial.print("Value X is: ");
    Serial.print(x);
    Serial.println(" mT");
    Serial.print("Value Y is: ");
    Serial.print(y);
    Serial.println(" mT");
    Serial.print("Value Z is: ");
    Serial.print(z);
    Serial.println(" mT");
    Serial.print("\n\n\n\n");

    delay(1000);

    Serial.print("count : ");
    Serial.println(count);

    if( ++count == 4 ) {
        Serial.println("\nBefore reset -------------------------------------------------------------------------------------------------------");

        /** Reset does not work for W2BW : either drive strength too low or delay to stabilize critical. */
        dut.reset(true, dut.getSensorType() != TLx493D_A1B6_e);

        Serial.println("\nAfter reset -------------------------------------------------------------------------------------------------------");
        count = 0;
    }
}
```

Once you compile and upload the example to your Arduino compatible board of choice, open the serial monitor, verify that your baud rate setting matches the example, and you should see measurements for the three axes being printed. If you wave a magnet near the sensor you can see the values changing!

![](https://cdn-learn.adafruit.com/assets/assets/000/133/866/medium800/sensors_Screenshot_2024-11-30_at_8.30.28_AM.png?1732985110)

# Adafruit TLV493 Triple-Axis Magnetometer

## Python & CircuitPython

It's easy to use the TLD493D with CircuitPython and the&nbsp;[Adafruit CircuitPython TLV493D](https://github.com/adafruit/Adafruit_CircuitPython_TLV493D)&nbsp;module.&nbsp; This module allows you to easily write Python code that reads the three-dimensional magnetic field measurements.  
  
You can use this sensor with any CircuitPython microcontroller board or with a Linux single board computer that has GPIO and Python&nbsp;[thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

# CircuitPython Microcontroller Wiring
Wiring the TLV493D is easy, since it only requires power and two wires for an I2C connection. Additionally, the STEMMA QT connectors give you additional solderless options for wiring:

- **Board 3V** &nbsp;to&nbsp;**sensor VIN (red wire)**
- **Board GND** &nbsp;to&nbsp;**sensor GND (black wire)**
- **Board SCL** &nbsp;to&nbsp;**sensor SCL (yellow wire)**
- **Board SDA** &nbsp;to&nbsp;**sensor SDA (blue wire)**  

![sensors_cpy_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/080/443/medium640/sensors_cpy_wiring.png?1567618615)

![sensors_cpy_breadboard_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/080/447/medium640/sensors_cpy_breadboard_wiring.png?1567619931)

## Python Computer Wiring

Since there's&nbsp;_dozens_&nbsp;of Linux computers/boards you can use we will show wiring for [Raspberry Pi](https://www.adafruit.com/product/3055). For other platforms,&nbsp;[please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V** &nbsp;to&nbsp;**sensor VIN (red wire)**
- **Pi GND** &nbsp;to&nbsp;**sensor GND (black wire)**
- **Pi SCL** &nbsp;to&nbsp;**sensor SCL (yellow wire)**
- **Pi SDA** &nbsp;to&nbsp;**sensor SDA (blue wire)**

![sensors_rpi_fritz.png](https://cdn-learn.adafruit.com/assets/assets/000/080/444/medium640/sensors_rpi_fritz.png?1567618654)

![sensors_rpi_breadboard_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/080/449/medium640/sensors_rpi_breadboard_wiring.png?1567619992)

## CircuitPython Installation of the TLV493D Library

You'll need to install the&nbsp;[Adafruit CircuitPython TLV394D](https://github.com/adafruit/Adafruit_CircuitPython_TLV493D) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_tlv493d.mpy**
- **adafruit\_bus\_device**

Before continuing make sure your board's **lib** folder or root filesystem has the&nbsp; **adafruit\_tlv493d.mpy&nbsp;** and&nbsp; **adafruit\_bus\_device** &nbsp;files and folders **&nbsp;** copied over.

Next&nbsp;[connect to the board's serial REPL&nbsp;](https://learn.adafruit.com/welcome-to-circuitpython/the-repl)so you are at the CircuitPython&nbsp;`>>>`&nbsp;prompt.

## Python Installation of TLV493D Library

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.&nbsp;[Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-tlv493d`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

## CircuitPython & Python Usage

To demonstrate the usage of the sensor we'll initialize it and read the magnetic measurements from the board's Python REPL.

Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

![](https://cdn-learn.adafruit.com/assets/assets/000/080/387/medium800/sensors_repl_setup.png?1567565033)

Now you're ready to read the **magnetic** values from the sensor using the property provided by the library.&nbsp;  
  
Here is an example showing how to print the magnetic values:

![](https://cdn-learn.adafruit.com/assets/assets/000/080/812/medium800/sensors_cp_repl_mag.png?1568184656)

You can find more details about what the library allows by reading the&nbsp;[library documentation](https://circuitpython.readthedocs.io/projects/tlv493d/en/latest/).  
  
That's it! Using the TLD493D 3-axis magnetometer with CircuitPython makes it easy to get started.

# Example Code
https://github.com/adafruit/Adafruit_CircuitPython_TLV493D/blob/main/examples/tlv493d_simpletest.py

# Adafruit TLV493 Triple-Axis Magnetometer

## Python Docs

# Adafruit TLV493 Triple-Axis Magnetometer

## Downloads

# Files

- [TLV493D Datasheet](https://www.infineon.com/dgdl/Infineon-TLV493D-A1B6-DS-v01_00-EN.pdf?fileId=5546d462525dbac40152a6b85c760e80)
- [TLV493D User Manual](https://www.infineon.com/dgdl/Infineon-TLV493D-A1B6_3DMagnetic-UM-v01_03-EN.pdf?fileId=5546d46261d5e6820161e75721903ddd)
- [EagleCAD files on GitHub](https://www.github.com/adafruit/Adafruit-TLV493D-PCB)
- [Fritzing object in Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20TLV493D.fzpz)

# Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/080/367/medium800/sensors_schematic.png?1567545196)

# Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/080/368/medium800/sensors_fab_print.png?1567545214)


## Primary Products

### Adafruit TLV493D Triple-Axis Magnetometer - STEMMA QT / Qwiic

[Adafruit TLV493D Triple-Axis Magnetometer - STEMMA QT / Qwiic](https://www.adafruit.com/product/4366)
The TLV493D 3-axis magnetometer is a great little sensor for detecting magnets[_ **in 3D** _.](https://www.youtube.com/watch?v=3FQDUX6X6-w) In fact, the manufacturer Infineon suggests it could be used to make a joystick! You could...

In Stock
[Buy Now](https://www.adafruit.com/product/4366)
[Related Guides to the Product](https://learn.adafruit.com/products/4366/guides)

## Featured Products

### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)

## Related Guides

- [LSM303 Accelerometer + Compass Breakout](https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout.md)
- [MPR121 Capacitive Touch Sensor on Raspberry Pi & BeagleBone Black](https://learn.adafruit.com/mpr121-capacitive-touch-sensor-on-raspberry-pi-and-beaglebone-black.md)
- [3D-Printed Bionic Eye](https://learn.adafruit.com/3d-printed-bionic-eye.md)
- [Adafruit MPR121 12-Key Capacitive Touch Sensor Breakout Tutorial](https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial.md)
- [Adafruit BMP280 Barometric Pressure + Temperature Sensor Breakout](https://learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout.md)
- [Adafruit DPI Display Kippah](https://learn.adafruit.com/adafruit-dpi-display-kippah-ttl-tft.md)
- [Adafruit Powerboost 1000C](https://learn.adafruit.com/adafruit-powerboost-1000c-load-share-usb-charge-boost.md)
- [Monochron](https://learn.adafruit.com/monochron.md)
- [Introducing Adafruit Trellis ](https://learn.adafruit.com/adafruit-trellis-diy-open-source-led-keypad.md)
- [Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout](https://learn.adafruit.com/adafruit-lsm9ds1-accelerometer-plus-gyro-plus-magnetometer-9-dof-breakout.md)
- [Adafruit H3LIS331 and LIS331 High-g 3-Axis Accelerometers](https://learn.adafruit.com/adafruit-h3lis331-and-lis331hh-high-g-3-axis-accelerometers.md)
- [Adafruit HTS221 - Temperature & Humidity Sensor](https://learn.adafruit.com/adafruit-hts221-temperature-humidity-sensor.md)
- [Your First Power Switch Relay Project - Circuit Playground Smart Plug](https://learn.adafruit.com/beginner-first-project-power-switch-relay-circuit-playground-smart-plug.md)
- [Adafruit Pi Stemma QT Breakout](https://learn.adafruit.com/adafruit-pi-stemma-qt-breakout.md)
- [No-Code IoT Soil Sensor](https://learn.adafruit.com/soil-node.md)
