Overview
The Adafruit TMAG5273 3D Hall Effect Magnetometer Breakout is a low-power linear 3D Hall-effect sensor designed for a wide range of industrial and personal electronics applications. It integrates three independent Hall-effect magnetometer sensors in the X, Y, and Z axes for full 3D orientation detection. The built-in 12-bit ADC can read the signal from each axis for read-out over I2C, it even has a thermometer built in for basic temperature reading!
An integrated angle calculation engine (CORDIC) provides full 360° angular position information for both on-axis and off-axis angle measurements. The angle calculation is performed using two user-selected magnetic axes over I2C. The TMAG also features magnetic gain and offset correction - note you'll have to manage the values and write them into the chip on boot-up.
3D Hall effect sensors are great for sensing rotation or motion of an object nearby with a magnet embedded inside: often used for magnetic rotary encoders or joysticks that don't have mechanical switches and thus are more reliable and don't fail from wear.
This sensor comes in two flavors, the A1 type is ±40mT / ±80mT range (you can pick either range), and the A2 has a wider ±133mT / ±266mT range. Both use the exact same firmware and pinout - the firmware we've written can detect which one you have plugged in and automatically scale the readings as necessary. This isn't a great sensor for measuring the magnetic field of the earth, much better for magnets of the ferric or rare-earth persuasion.
To make life easier so you can focus on your important work, we've taken the TMAG5723 and put it onto a breakout PCB along with support circuitry to let you use this little wonder with 3.3V (Feather/Raspberry Pi) or 5V (Arduino/ Metro328) logic levels. Additionally, since it speaks I2C, you can easily connect it up with two wires (plus power and ground!). We've even included SparkFun qwiic compatible STEMMA QT connectors for the I2C bus so you don't even need to solder! Just wire up to your favorite micro and you can use our CircuitPython/Python or Arduino drivers to easily interface with the TMAG and get magnetic measurements ASAP.
It's fully assembled and tested. Comes with a bit of 0.1" standard header in case you want to use it with a breadboard or perfboard. Four 2.5mm (0.1") mounting holes for easy attachment.
Page last edited March 24, 2026
Text editor powered by tinymce.
Pinouts
The default I2C address is 0x35.
Power Pins
- VIN - this is the power pin. 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. For a 3.3V microcontroller, use 3.3V.
- 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 - I2C clock pin, connect to your microcontroller I2C clock line. This pin is level shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.
- SDA - I2C data pin, connect to your microcontroller I2C data line. This pin is level shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.
- STEMMA QT - These connectors allow you to connect to dev boards with STEMMA QT connectors or to other things with various associated accessories.
Page last edited March 24, 2026
Text editor powered by tinymce.
CircuitPython and Python
It's easy to use the TMAG5273 with Python or CircuitPython, and the Adafruit_CircuitPython_TMAG5273 module. This module allows you to easily write Python code that allows you to read the TMAG5273 magnetometer. You can use this magnetometer with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
CircuitPython Microcontroller Wiring
First, wire up an TMAG5273 to your board exactly as shown below. Here's an example of wiring a Feather RP2040 to the TMAG5273 with I2C using one of the handy STEMMA QT connectors:
-
Board STEMMA 3V to breakout STEMMA VIN (red wire)
-
Board STEMMA GND to breakout STEMMA GND (black wire)
-
Board STEMMA SCL to breakout STEMMA SCL (yellow wire)
- Board STEMMA SDA to breakout STEMMA SDA (blue wire)
You can also use standard 0.100" pitch headers to wire it up on a breadboard:
-
Board 3V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
Python Computer Wiring
Since there's dozens of Linux computers/boards you can use, below shows wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired to the magnetometer using I2C and a STEMMA QT connector:
-
Pi 3V to breakout STEMMA VIN (red wire)
-
Pi GND to breakout STEMMA GND (black wire)
-
Pi SCL to breakout STEMMA SCL (yellow wire)
- Pi SDA to breakout STEMMA SDA (blue wire)
Finally, here is an example of how to wire up a Raspberry Pi to the magnetometer using a solderless breadboard:
-
Pi 3V to breakout VIN (red wire)
-
Pi GND to breakout GND (black wire)
-
Pi SCL to breakout SCL (yellow wire)
- Pi SDA to breakout SDA (blue wire)
Python Installation of TMAG5273 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. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
pip3 install adafruit-circuitpython-tmag5273
If your default Python is version 3, you may need to run pip instead. Make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
CircuitPython Usage
To use with CircuitPython, you need to first install the TMAG5273 library and its dependencies into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folders and file:
- adafruit_bus_device/
- adafruit_register/
- adafruit_tmag5273.mpy
Python Usage
Once you have the library pip3 installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:
python3 code.py
Example Code
If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
If running Python: The console output will appear wherever you are running Python.
# SPDX-FileCopyrightText: Copyright (c) 2026 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
import adafruit_tmag5273
i2c = board.I2C()
sensor = adafruit_tmag5273.TMAG5273(i2c)
while True:
mag_x, mag_y, mag_z = sensor.magnetic
temp = sensor.temperature
print(f"X: {mag_x:.2f} uT Y: {mag_y:.2f} uT Z: {mag_z:.2f} uT Temp: {temp:.1f} °C")
time.sleep(1)
In the example, the temperature sensor is instantiated on I2C. Then, in the loop, the X, Y and Z readings from the magnetometer, along with temperature readings, are printed to the serial console every second. This sensor is meant for sensing rotation or motion of an object nearby with a magnet embedded inside. It is not meant for measuring the magnetic field of the earth.
Page last edited March 24, 2026
Text editor powered by tinymce.
Arduino
Using the TMAG5273 magnetometer with Arduino involves wiring up the magnetometer to your Arduino-compatible microcontroller, installing the Adafruit_TMAG5273 library and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the TMAG5273 VIN.
Here is an Adafruit Metro wired up to the TMAG5273 using the STEMMA QT connector:
-
Board 5V to breakout STEMMA VIN (red wire)
-
Board GND to breakout STEMMA GND (black wire)
-
Board SCL to breakout STEMMA SCL (yellow wire)
- Board SDA to breakout STEMMA SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
Library Installation
You can install the Adafruit TMAG5273 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit TMAG5273, and select the Adafruit TMAG5273 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
/*!
* @file simpletest.ino
* @brief Simple test for the Adafruit TMAG5273 3-axis Hall-effect sensor
*
* Reads magnetic field (X, Y, Z in uT) and temperature, prints to serial.
*
* Written by Limor 'ladyada' Fried with assistance from Claude Code
* MIT license
*/
#include <Adafruit_TMAG5273.h>
Adafruit_TMAG5273 tmag;
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
Serial.println(F("Adafruit TMAG5273 Simple Test"));
if (!tmag.begin()) {
Serial.println(F("Failed to find TMAG5273 sensor!"));
while (1) {
delay(10);
}
}
Serial.println(F("TMAG5273 found!"));
Serial.print(F("Manufacturer ID: 0x"));
Serial.println(tmag.getManufacturerID(), HEX);
Serial.print(F("Device ID: 0x"));
Serial.println(tmag.getDeviceID(), HEX);
bool is_x2 = (tmag.getDeviceID() & 0x03) == 0x02;
Serial.print(F("Variant: "));
Serial.println(is_x2 ? F("x2 (+/-133/266 mT)") : F("x1 (+/-40/80 mT)"));
}
void loop() {
float x = tmag.readMagneticX();
float y = tmag.readMagneticY();
float z = tmag.readMagneticZ();
float temp = tmag.getTemperature();
Serial.print(F("X: "));
Serial.print(x, 1);
Serial.print(F(" uT\tY: "));
Serial.print(y, 1);
Serial.print(F(" uT\tZ: "));
Serial.print(z, 1);
Serial.print(F(" uT\tT: "));
Serial.print(temp, 1);
Serial.println(F(" C"));
delay(100);
}
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You should see that the sketch has found your connected TMAG5273 sensor. It will also print out the variant type (A1 or A2). Then, you'll see the X, Y and Z readings along with the temperature reading printed to the Serial Monitor every second. This sensor is meant for sensing rotation or motion of an object nearby with a magnet embedded inside. It is not meant for measuring the magnetic field of the earth.
Page last edited March 24, 2026
Text editor powered by tinymce.
Downloads
Files
Page last edited March 24, 2026
Text editor powered by tinymce.