# MLX90393 Wide-Range 3-Axis Magnetometer

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/099/579/medium800/sensors_MLX30393_top.jpg?1613592046)

Measure the invisible magnetic fields that surround us, with this wide-range magnetometer. The MLX90393 is a wide range magnetic field sensor, that can measure 16-bits in ranges from +/-5mT up to +/-50mT in all 3 axes.

Compared to most magenetometers, this gives a huge range, which makes it excellent for detecting _magnets_ and magnetic orientation, rather than the Earths magnetic field. (Magnets have a much stronger field that overwhelms most magnetometers that would normally be used for orientation with respect to the North Pole)

![](https://cdn-learn.adafruit.com/assets/assets/000/099/580/medium800/sensors_MLX30393_back.jpg?1613592057)

To make it easy to use, we've placed this tiny little sensor onto a breakout board, with a 3.3V power supply and level shifter. This makes it easy to use with any 3 or 5V microcontroller. Our Arduino and CircuitPython code will get you started in a jiffy, with I2C communication to the sensor. You will be readin' out those Gauss's in minutes! With the address select pins you can have up to 4 sensors on one I2C bus.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/581/medium800/sensors_MLX30393_top_header.jpg?1613592180)

Comes as a fully assembled and tested breakout board with a small piece of header for use with a breadboard. As if that weren't enough, we've now also added[&nbsp;SparkFun qwiic](https://www.sparkfun.com/qwiic)&nbsp;compatible&nbsp;**[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)**&nbsp;connectors for the I2C bus **so you don't even need to solder the I2C and power lines.** Just wire up to your favorite micro using a&nbsp;[STEMMA QT adapter cable.](https://www.adafruit.com/?q=stemma%20qt%20cable)&nbsp;The Stemma QT connectors also mean the MLX90393 can be used with our&nbsp;[various associated accessories.](https://www.adafruit.com/?q=JST%20SH%204)&nbsp;[QT Cable is not included, but we have a variety in the shop](https://www.adafruit.com/?q=stemma+qt+cable&sort=BestMatch).

![](https://cdn-learn.adafruit.com/assets/assets/000/099/582/medium800/sensors_MLX30393_STEMMA_side.jpg?1613592188)

# Specifications

The MLX90393 has the following key technical specifications:

- 16-bit output on all three (XYZ) magnetic field sensors
- An unusually large dynamic range of **5-50 mT** (1 mT or millitesla = 10 G or Gauss).  
By comparison, the LSM303DLHC saturates at +/-8.1 G (0.81 mT) at maximum range setting.
- Up to ~500 Hz sample rate [1]
- User-adjustable I2C address to allow multiple sensors in your project (two I2C ADDR pins for four possible I2C addresses).

[1] Based on `OSR=0, DIG_FILT=2, HALLCONF=0xC` for **1.84ms** conversion time. See 15.1.5 HALLCONF [3:0} in the datasheet for details.

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/071/117/medium800/sensors_4022_kit_ORIG_2019_02.jpg?1550086571)

# MLX90393 Wide-Range 3-Axis Magnetometer

## Pinout

The MLX90393 3-Axis magnetometer breakout has the following pins:

![](https://cdn-learn.adafruit.com/assets/assets/000/099/583/medium800/sensors_MLX30393_pinouts.jpg?1613592364)

![](https://cdn-learn.adafruit.com/assets/assets/000/071/005/medium800/sensors_4022-top-wide.png?1549900701)

# Power Pins

This breakout board can be run on&nbsp; **3.3V** and&nbsp; **5V** systems, although only the&nbsp; **SCL&nbsp;** and&nbsp; **SDA** lines are 5V safe (other pins like INT will need to be manually level-shifted by you).

- **VIN** - This is the input to the 3.3V voltage regulator, which makes it possible to use the 3.3V sensor on 5V systems. It also determines the logic level of the SCL and SDA pins. Connect this to&nbsp; **3.3V** on the MCU for 3.3V boards (Adafruit Feathers), or&nbsp; **5.0V** for 5V Arduinos (Arduino Uno, etc.).
- **3VO** - This is the&nbsp; **OUTPUT** of the 3.3V regulator, and can be used to provide 3.3V power to other parts of your project if required (\<100mA).
- **GND** - Connect this to the&nbsp; **GND** pin on your development board to make sure they are sharing a common GND connection, or the electrons won't have anywhere to flow!

Danger: 

# Digital Pins

- **SCL** - The clock line on the I2C bus. This pin has an internal pullup resistor on the PCB, which is required as part of the I2C spec, meaning you don't need to add one externally yourself.
- **SDA** &nbsp;- The data line on the I2C bus. This pin has an internal pullup resistor on the PCB, which is required as part of the I2C spec, meaning you don't need to add one externally yourself.
- **INT** - This INT pin can be configured to 'fire' whenever a new data sample is read in single measurement mode, which is what the device boots up to by default in our driver.

On the top row, you have a few more rarely used specialty pins, though normally you will simply leave these unsoldered and unconnected:

- **A0&nbsp;** and&nbsp; **A1** : These two pins are LOW (0) by default, but if you need to connect multiple MLX90393s to your MCU or resolve an address conflict, you can adjust the logic on these two pins which will change the last two bits of the I2C address that this breakout responds to. Most of the time, you will simply&nbsp; **leave these disconnected**. (On the original version, these pins were on the bottom row.)
- **CS (AKA SENB)** - This is used to set the sensor in I2C or SPI mode, but **this breakout only supports I2C** so the pin is provided purely for testing purposes unless you want to dig into writing your own SPI driver and making the required changes to the PCB.
- **TR** &nbsp;(AKA **INT/TRG** )&nbsp;- This pin can optionally be setup to fire an interrupt in addition to the&nbsp; **INT** pin, and is basically a mirror on INT when configured as such.
- **MIS** (AKA&nbsp; **TRIG** ) - This is used as MISO on the SPI bus, but SPI isn't supported on this breakout, so it is only provided to testing purposes.
- **G** - This is simply an additional GND pin, and can be left unconnected if not required.

# MLX90393 Wide-Range 3-Axis Magnetometer

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/071/146/medium800/sensors_4022-01.jpg?1550173841)

# Assembly
![](https://cdn-learn.adafruit.com/assets/assets/000/071/142/medium800/sensors_DSC_4017.jpg?1550173513)

## Prepare the header strip:

&nbsp;

Cut the strip to length if necessary. It will be easier to solder if you insert it into a breadboard -&nbsp; **long pins down**.

![sensors_DSC_4019.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/141/medium640/sensors_DSC_4019.jpg?1550173476)

## Add the MLX90393:

&nbsp;

Place the board over the pins so that the short pins poke through the top of the breakout pads.

![sensors_DSC_4020.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/140/medium640/sensors_DSC_4020.jpg?1550173379)

## And Solder!

&nbsp;

Be sure to solder all pins for reliable electrical contact.  
  
_(For tips on soldering, be sure to check out the&nbsp;_[_Guide to Excellent Soldering_](http://learn.adafruit.com/adafruit-guide-excellent-soldering)_)._

![sensors_DSC_4021.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/143/medium640/sensors_DSC_4021.jpg?1550173550)

![sensors_DSC_4023.jpg](https://cdn-learn.adafruit.com/assets/assets/000/071/144/medium640/sensors_DSC_4023.jpg?1550173625)

OK, you're done!

You can now plug in your Magnetometer and start measuring some magnetic fields!

![](https://cdn-learn.adafruit.com/assets/assets/000/071/145/medium800/sensors_DSC_4026.jpg?1550173680)

# MLX90393 Wide-Range 3-Axis Magnetometer

## Arduino

# Wiring

Hooking up the MLX90393 to your Feather or Arduino is easy:

- If you are running a Feather (3.3V), connect the&nbsp; **3V** pin to **3.3V** on the MLX90393 **(red wire on STEMMA QT version)**
- If you are running a 5V Arduino (Uno, etc.), connect&nbsp; **5V** to **5V** on the MLX90393 **(red wire on STEMMA QT version)**
- Connect&nbsp; **GND** on the MCU to&nbsp; **GND** on the MLX90393 **(black wire on STEMMA QT version)**
- &nbsp; **Arduino**  **SCL** to **MLX90393 SCL** **(yellow wire on STEMMA QT version)**
- **Arduino**  **SDA** to **MLX90393 SDA** **(blue wire on STEMMA QT version)**

![sensors_MLX30393_Arduino_STEMMA_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/587/medium640/sensors_MLX30393_Arduino_STEMMA_bb.jpg?1613596253)

![sensors_MLX30393_Arduino_breadboard_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/588/medium640/sensors_MLX30393_Arduino_breadboard_bb.jpg?1613596270)

![sensors_MLX30393_arduino_original.png](https://cdn-learn.adafruit.com/assets/assets/000/099/589/medium640/sensors_MLX30393_arduino_original.png?1613596285)

The final results should resemble the illustration above, showing an Adafruit Metro development board.

Info: 

# Installation

You can install the **Adafruit MLX90393 Library** for Arduino using the Library Manager in the Arduino IDE:

![](https://cdn-learn.adafruit.com/assets/assets/000/070/878/medium800/sensors_managelib.png?1549563719)

Click the&nbsp; **Manage Libraries ...** menu item, search for **Adafruit MLX90393** ,&nbsp;and select the&nbsp; **Adafruit MLX90393** library:

![](https://cdn-learn.adafruit.com/assets/assets/000/070/876/medium800/sensors_Screenshot_2019-02-06_at_02.45.24.png?1549563652)

# Load Example

Open up&nbsp; **File -\> Examples -\> Adafruit MLX90393&nbsp;**** -\>&nbsp;basicdemo&nbsp;**and upload to your Arduino wired up to the sensor

Upload the sketch to your board and open up the Serial Monitor ( **Tools-\>Serial Monitor** ). You should see the temperature in&nbsp;magnetic field values for X/Y/Z.

# Example Code

The following example code is part of the standard library, but illustrates how you can retrieve sensor data from the MLX90393 for the X, Y and Z axis:

https://github.com/adafruit/Adafruit_MLX90393_Library/blob/master/examples/basicdemo/basicdemo.ino

You should get something resembling the following output when you open the Serial Monitor at 9600 baud:

![](https://cdn-learn.adafruit.com/assets/assets/000/071/120/medium800/sensors_Screenshot_2019-02-13_at_22.08.12.png?1550092109)

# Setting the Gain

The driver will default to 1x gain, but if you wish to adjust the gain you can do so using the ``setGain(enum mlx90393_gain gain)`` function, passing in one of the following values:

```auto
enum  mlx90393_gain {
    MLX90393_GAIN_5X          = (0x00),
    MLX90393_GAIN_4X,
    MLX90393_GAIN_3X,
    MLX90393_GAIN_2_5X,
    MLX90393_GAIN_2X,
    MLX90393_GAIN_1_67X,
    MLX90393_GAIN_1_33X,
    MLX90393_GAIN_1X
};
```

For example, to set the gain to 2x you would call the function as follows:

```auto
sensor.setGain(MLX90393_GAIN_2X);
```

Resolution is managed internally in the driver itself, and defaults to the maximum value of +/- 2^15 LSBs.

# MLX90393 Wide-Range 3-Axis Magnetometer

## Arduino API

# MLX90393 Wide-Range 3-Axis Magnetometer

## Python and CircuitPython

Using the MLX90393 with CircuitPython is easy. The [Adafruit\_CircuitPython\_MLX90393](https://github.com/adafruit/Adafruit_CircuitPython_MLX90393) repo on Github always contains the latest public code, and allows you to quickly and easily get started with the Adafruit MLX90393 breakout board.

# CircuitPython Wiring

The diagram below shows how you can wire up your CircuitPython board (in Feather form below) to the MLX90393:

Simple connect:

- **3V** on the dev board to&nbsp; **VIN** on the MLX90393 **(red wire on STEMMA QT version)**
- **GND** on the dev board to&nbsp; **GND** on the MLX90393 **(black wire on STEMMA QT version)**
- **SCL** on the dev board to&nbsp; **SCL** on the MLX90393 **(yellow wire on STEMMA QT version)**
- **SDA** on the dev board to **SDA** on the MLX90393 **(blue wire on STEMMA QT version)**

![sensors_MLX30393_Feather_STEMMA_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/590/medium640/sensors_MLX30393_Feather_STEMMA_bb.jpg?1613596476)

![sensors_MLX30393_Feather_breadboard_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/591/medium640/sensors_MLX30393_Feather_breadboard_bb.jpg?1613596488)

![sensors_MLX30393_Feather_original.png](https://cdn-learn.adafruit.com/assets/assets/000/099/592/medium640/sensors_MLX30393_Feather_original.png?1613596499)

# Python Wiring

Since there's&nbsp;_dozens_&nbsp;of Linux computers/boards you can use we will show wiring for Raspberry Pi. 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;

Make the following connections between the Pi and the MLX90393:

Simple connect:

- **3.3V** on the RPi to&nbsp; **VIN** on the MLX90393 **(red wire on STEMMA QT version)**
- **GND** on the RPi to&nbsp; **GND** on the MLX90393 **(black wire on STEMMA QT version)**
- **SCL** on the RPi to&nbsp; **SCL** on the MLX90393 **(yellow wire on STEMMA QT version)**
- **SDA** on the RPi to **SDA** on the MLX90393 **(blue wire on STEMMA QT version)**

![sensors_MLX30393_RasPi_STEMMA_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/593/medium640/sensors_MLX30393_RasPi_STEMMA_bb.jpg?1613596791)

![sensors_MLX30393_RasPi_breadboard_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/099/594/medium640/sensors_MLX30393_RasPi_breadboard_bb.jpg?1613596813)

![sensors_MLX30393_RasPi_original.png](https://cdn-learn.adafruit.com/assets/assets/000/099/595/medium640/sensors_MLX30393_RasPi_original.png?1613596826)

# Library Installation

You'll need to install the [Adafruit CircuitPython MLX90393](https://github.com/adafruit/Adafruit_CircuitPython_MLX90393) 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&nbsp;[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\_mlx90393.mpy**
- **adafruit\_bus\_device**

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_mlx90393.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/micropython-basics-how-to-load-micropython-on-a-board/serial-terminal)so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

# Python Installation of the MLX90393 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:

- `pip3 install adafruit-circuitpython-mlx90393`

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!

# Example

The following example shows a minimal python script to make use of the MLX90393.

Running this example, a three axis magnetic field measurement will be read every second, and displayed via the serial output. A timestamp will precede each sample, and if any error condition was encountered during the read attempt, the details of the error code will be displayed:

https://github.com/adafruit/Adafruit_CircuitPython_MLX90393/blob/main/examples/mlx90393_simpletest.py

If you open the&nbsp; **Serial** tab in mu-editor with the sample code running, you should get output resembling the following if everything was setup correctly:

![](https://cdn-learn.adafruit.com/assets/assets/000/071/119/medium800/sensors_Screenshot_2019-02-13_at_20.48.58.png?1550087349)

# Adjusting Gain

The gain on the sensor can be adjusted via the `.gain` property, as shown below:

```auto
SENSOR.gain = adafruit_mlx90393.GAIN_2X
```

 **Alternatively** , you can set the gain property via the constructor, as shown below:

```auto
SENSOR = adafruit_mlx90393.MLX90393(I2C_BUS, gain=adafruit_mlx90393.GAIN_1X)
```

The value assigned to the `gain` property can be one of the following entries:

- GAIN\_5X
- GAIN\_4X
- GAIN\_3X
- GAIN\_2\_5X
- GAIN\_2X
- GAIN\_1\_67X
- GAIN\_1\_33X
- GAIN\_1X  
  

Resolution is managed internally in the driver itself, and defaults to the maximum value of +/- 2^15 LSBs.

# MLX90393 Wide-Range 3-Axis Magnetometer

## Python Docs

# MLX90393 Wide-Range 3-Axis Magnetometer

## Downloads

# Downloads and Design Files

- [Board Files on Github](https://github.com/adafruit/Adafruit-MLX90393-PCB)
- [Manufacturer's Product Page](https://www.melexis.com/en/product/MLX90393/Triaxis-Micropower-Magnetometer)
- [Arduino Library on Github](https://github.com/adafruit/Adafruit_MLX90393_Library) (for PRs and driver development!)
- [CircuitPython Library on Github](https://github.com/adafruit/Adafruit_CircuitPython_MLX90393)
- [Fritzing Part](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20MLX90393.fzpz)
- [3D models on GitHub](https://github.com/adafruit/Adafruit_CAD_Parts/tree/main/4022%20MLX90393%20QT)

# Datasheet

You can download the datasheet for this chip using the following link:

[MLX90393-Datasheet-Melexis.pdf](https://cdn-learn.adafruit.com/assets/assets/000/069/600/original/MLX90393-Datasheet-Melexis.pdf?1547824268)
# Schematic for STEMMA QT Version
![](https://cdn-learn.adafruit.com/assets/assets/000/099/584/medium800/sensors_MLX30393_sch.png?1613595458)

# Fab Print for STEMMA QT Version
![](https://cdn-learn.adafruit.com/assets/assets/000/099/585/medium800/sensors_MLX30393_fab_print.png?1613595466)

# 3D model for STEMMA QT Version
![](https://cdn-learn.adafruit.com/assets/assets/000/147/393/medium800/sensors_4022_MLX90393_QT.jpg?1793641370 )

# Schematic for Original Version

The schematic for this breakout is available below:

![](https://cdn-learn.adafruit.com/assets/assets/000/069/601/medium800/sensors_MLC90303_REV-C_Schematic.png?1547824490)

# Board Layout for Original Version

The breakout has the following physical dimensions:

![](https://cdn-learn.adafruit.com/assets/assets/000/069/603/medium800/sensors_MLX90393_Dimensions.png?1547825153)


## Primary Products

### Adafruit Wide-Range Triple-axis Magnetometer - MLX90393

[Adafruit Wide-Range Triple-axis Magnetometer - MLX90393](https://www.adafruit.com/product/4022)
Measure the invisible magnetic fields that surround us, with this wide-range magnetometer. The MLX90393 is a wide range magnetic field sensor, that can measure 16-bits in ranges from ±5mT up to ±50mT in all 3 axes.

Compared to most magnetometers, this gives a huge range,...

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

## Related Guides

- [Reading QR Codes with the Tiny Code Reader](https://learn.adafruit.com/reading-qr-codes-with-the-tiny-code-reader.md)
- [Moonshine Voice Control on Raspberry Pi](https://learn.adafruit.com/moonshine-voice-control-on-raspberry-pi.md)
- [MIDI Breath Controller](https://learn.adafruit.com/midi-breath-controller.md)
- [Adafruit SensorLab - Magnetometer Calibration](https://learn.adafruit.com/adafruit-sensorlab-magnetometer-calibration.md)
- [Bluefruit Playground App](https://learn.adafruit.com/bluefruit-playground-app.md)
- [Rotary Encoder in CircuitPython](https://learn.adafruit.com/rotary-encoder.md)
- [Adafruit IO Basics: Servo](https://learn.adafruit.com/adafruit-io-basics-servo.md)
- [Sensor Plotting with Mu and CircuitPython](https://learn.adafruit.com/sensor-plotting-with-mu-and-circuitpython.md)
- [Comparing Gyroscope Datasheets](https://learn.adafruit.com/comparing-gyroscope-datasheets.md)
- [Adafruit ICM20649 Wide-Range 6-DoF IMU Accelerometer and Gyro](https://learn.adafruit.com/adafruit-icm20649-wide-range-6-dof-imu-accelerometer-and-gyro.md)
- [Digi-Key IoT Studio Mini Smart Home](https://learn.adafruit.com/digikey-iot-studio-smart-home.md)
- [No-Code Offline Data Logger with WipperSnapper](https://learn.adafruit.com/no-code-offline-data-logging-with-wippersnapper.md)
- [Integrating Home Assistant with Adafruit IO](https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant.md)
- [ShotTracker Teardown](https://learn.adafruit.com/shottracker-teardown.md)
- [CircuitPython Libraries on Linux and Google Coral](https://learn.adafruit.com/circuitpython-on-google-coral-linux-blinka.md)
