Part

Magnetometer, LIS3MDL

The Earth's field on three axes, up to 6842 counts a gauss, for a compass heading.

See every part
  • 6 pins
  • 4 settings
  • In 1 project
Drawn live by the editor's own code, at the size you see it.
Magnetometer, LIS3MDL as drawn in the Mokxi simulator
At a glance

The Magnetometer, LIS3MDL in brief

What it is, and every setting the properties panel gives it.

The LIS3MDL is ST’s three-axis magnetometer, read over I2C at 0x1C, up to 6842 counts a gauss: the sensor of a digital compass. Flat on the bench it reads the Earth’s field, about 20 microtesla toward magnetic north and 45 down at mid-northern latitudes, and atan2 of the two horizontal readings is the heading. VIN and GND take 3 V to 5 V on the board, SCL and SDA are I2C with the pull-ups on the board, DRDY is low while a new sample waits and INT is the threshold interrupt, left high-impedance by the model. The part’s pitch, roll and heading are sliders, and address is 28, which is 0x1C.

Family
Sensors
Pins
6
address
28
pitch
0
roll
0
heading
0
Pins

6 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
VIN
Supply, 3 to 5 V on the board.
GND
Ground.
SCL
I2C. The board carries the pull-ups.
SDA
I2C. The board carries the pull-ups.
DRDY
Low while a new sample waits.
INT
The threshold interrupt, left high-Z by the model.
How to use it

How to read an LIS3MDL magnetometer with an Arduino

The magnetometer’s VIN goes to 5 V, GND to GND, SDA to A4 and SCL to A5, at address 0x1C. The project puts an LSM6DSOX accelerometer and gyroscope beside it on the same bus: the three sensors a drone or a head tracker needs, which way is down, how fast it turns and which way is north. Pitch comes from the accelerometer alone, and the gyroscope reads the turn rate only while the board is moving.

The heading comes from atan2 of the two horizontal field readings. Drag the heading slider on the LIS3MDL, and the pitch and heading sliders on the LSM6DSOX to see the gyro move. The sketch uses the Adafruit LSM6DSOX and LIS3MDL libraries.

Part pin
Board pin
VIN
5 V
GND
GND
SDA
A4
SCL
A5
DRDY, INT
Not wired

The board takes 3 V to 5 V, so a 3.3 V board such as an ESP32 or a Pico drives it directly. Use that board’s I2C pins; the address is 0x1C.

Nine axeslive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Common errors

Common Magnetometer, LIS3MDL errors and fixes

What goes wrong
The fix
The heading is off by a fixed amount.
It is relative to magnetic north, not true north, and anything magnetic nearby bends it. Keep the sensor flat and away from motors and magnets.
The sensor is not found.
It answers at 0x1C. Check SDA and SCL against the table; the board carries the pull-ups.
The tilted heading is wrong.
The simple atan2 of the two horizontal readings holds only when the board is flat. Tilt needs the accelerometer’s pitch and roll.
Questions

Questions and answers

What is the I2C address of the LIS3MDL?

0x1C.

How do I get a compass heading from a magnetometer?

Take atan2 of the two horizontal readings while the board is flat. Flat on the bench it reads about 20 microtesla toward magnetic north.

How sensitive is the LIS3MDL?

Up to 6842 counts a gauss.

How it is modeled

What is true about the Magnetometer, LIS3MDL, here

In its help article’s own words: what the simulation gets right, and where it stops.

Not modeled

The interrupt threshold, the self-test, offsets, noise, and nearby magnets.

From LIS3MDL magnetometer, in full.

Projects

See the Magnetometer, LIS3MDL in a project

One built-in project uses it. It opens in the editor, already wired.

Boards

The boards it is shown on

This board has a built-in project with the Magnetometer, LIS3MDL in it.

Wire up the Magnetometer, LIS3MDL

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.