Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use Adafruit LIS3MDL Triple-axis Magnetometer: Examples, Pinouts, and Specs

Image of Adafruit LIS3MDL Triple-axis Magnetometer
Cirkit Designer LogoDesign with Adafruit LIS3MDL Triple-axis Magnetometer in Cirkit Designer

Introduction

The Adafruit LIS3MDL Triple-axis Magnetometer is a compact and versatile sensor capable of measuring magnetic fields in three dimensions. It is designed to be used in a wide range of applications, including mobile phones, tablets, drones, and particularly for compass functionalities in navigation systems. The LIS3MDL is an ideal choice for projects requiring precise heading information or for detecting magnetic anomalies.

Explore Projects Built with Adafruit LIS3MDL Triple-axis Magnetometer

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Arduino Ethernet with LSM303DLHC Accelerometer and Compass Interface
Image of Compass: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
This circuit connects an Adafruit LSM303DLHC Triple-axis Accelerometer+Magnetometer (Compass) to an Arduino Board Ethernet using I2C communication protocol. The SCL and SDA pins of the sensor are connected to the A5 and A4 pins of the Arduino, respectively, for serial clock and data transfer. The sensor is powered by the Arduino's 5V output, and both devices share a common ground.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Mega 2560-Based Multi-Sensor System with Distance, Magnetometer, and Camera Integration
Image of Junior Design - Sensors: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
This circuit features an Arduino Mega 2560 microcontroller interfaced with multiple VL53L0X distance sensors, an OV7725 camera module, and an Adafruit LIS3MDL triple-axis magnetometer. The Arduino reads data from these sensors and the camera, likely for a robotics or environmental sensing application, and processes the data for further use or transmission.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO R4 WiFi and Adafruit LIS3DH Accelerometer-Based Motion Detection System
Image of circuit: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
This circuit consists of an Arduino UNO R4 WiFi connected to an Adafruit LIS3DH Triple-Axis Accelerometer via I2C communication. The Arduino reads acceleration data from the LIS3DH sensor and outputs it to the serial monitor for further analysis or processing.
Cirkit Designer LogoOpen Project in Cirkit Designer
Teensy 4.1 Based Biometric Data Acquisition System with AD8232 Heart Rate Monitor and LIS3DH Accelerometer
Image of Teensy 4.1 accelerometer: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
This circuit integrates a Teensy 4.1 microcontroller with an Adafruit LIS3DH Triple-Axis Accelerometer and an AD8232 Heart Rate Monitor. The accelerometer communicates with the Teensy via I2C (SCL and SDA lines), while the heart rate monitor's output and lead-off detection (LO+ and LO-) are connected to the Teensy's analog inputs. The circuit is designed to measure both acceleration and heart rate signals, likely for a wearable or health monitoring device.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with Adafruit LIS3MDL Triple-axis Magnetometer

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Compass: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
Arduino Ethernet with LSM303DLHC Accelerometer and Compass Interface
This circuit connects an Adafruit LSM303DLHC Triple-axis Accelerometer+Magnetometer (Compass) to an Arduino Board Ethernet using I2C communication protocol. The SCL and SDA pins of the sensor are connected to the A5 and A4 pins of the Arduino, respectively, for serial clock and data transfer. The sensor is powered by the Arduino's 5V output, and both devices share a common ground.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Junior Design - Sensors: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
Arduino Mega 2560-Based Multi-Sensor System with Distance, Magnetometer, and Camera Integration
This circuit features an Arduino Mega 2560 microcontroller interfaced with multiple VL53L0X distance sensors, an OV7725 camera module, and an Adafruit LIS3MDL triple-axis magnetometer. The Arduino reads data from these sensors and the camera, likely for a robotics or environmental sensing application, and processes the data for further use or transmission.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of circuit: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
Arduino UNO R4 WiFi and Adafruit LIS3DH Accelerometer-Based Motion Detection System
This circuit consists of an Arduino UNO R4 WiFi connected to an Adafruit LIS3DH Triple-Axis Accelerometer via I2C communication. The Arduino reads acceleration data from the LIS3DH sensor and outputs it to the serial monitor for further analysis or processing.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Teensy 4.1 accelerometer: A project utilizing Adafruit LIS3MDL Triple-axis Magnetometer in a practical application
Teensy 4.1 Based Biometric Data Acquisition System with AD8232 Heart Rate Monitor and LIS3DH Accelerometer
This circuit integrates a Teensy 4.1 microcontroller with an Adafruit LIS3DH Triple-Axis Accelerometer and an AD8232 Heart Rate Monitor. The accelerometer communicates with the Teensy via I2C (SCL and SDA lines), while the heart rate monitor's output and lead-off detection (LO+ and LO-) are connected to the Teensy's analog inputs. The circuit is designed to measure both acceleration and heart rate signals, likely for a wearable or health monitoring device.
Cirkit Designer LogoOpen Project in Cirkit Designer

Technical Specifications

Key Features

  • Magnetic field range: ±4/±8/±12/±16 gauss
  • Digital output: I²C/SPI
  • 16-bit data output
  • Power supply range: 2.5V to 5.5V
  • Low power consumption
  • Operating temperature range: -40°C to +85°C

Pin Configuration and Descriptions

Pin Number Name Description
1 VIN Supply voltage (2.5V to 5.5V)
2 GND Ground
3 SDA I²C Data / SPI Serial Data In (SDI)
4 SCL I²C Clock / SPI Serial Clock (SCK)
5 SDO SPI Serial Data Out (SDO) / I²C Address Selection
6 CS SPI Chip Select (Active Low)

Usage Instructions

Integration into a Circuit

To use the Adafruit LIS3MDL Triple-axis Magnetometer in a circuit:

  1. Connect the VIN pin to a 2.5V to 5.5V power supply.
  2. Connect the GND pin to the ground of your power supply.
  3. For I²C communication, connect the SDA and SCL pins to your microcontroller's I²C data and clock lines, respectively.
  4. For SPI communication, connect the SDA, SCL, SDO, and CS pins to your microcontroller's SPI data in, clock, data out, and chip select lines.

Best Practices

  • Ensure that the power supply is stable and within the specified voltage range.
  • Use pull-up resistors on the I²C lines if they are not already present on the microcontroller board.
  • Keep the magnetometer away from strong magnetic fields that could saturate the sensor and affect readings.
  • When using SPI, ensure that the CS pin is toggled correctly to avoid communication issues.

Example Code for Arduino UNO

Below is an example code snippet for interfacing the Adafruit LIS3MDL with an Arduino UNO using the I²C protocol. Before using the code, make sure to install the Adafruit LIS3MDL library through the Arduino Library Manager.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LIS3MDL.h>

Adafruit_LIS3MDL lis3mdl = Adafruit_LIS3MDL();

void setup() {
  Serial.begin(9600);
  while (!Serial) { delay(10); } // Wait for serial monitor to open

  Serial.println("LIS3MDL Magnetometer Test");
  
  if (!lis3mdl.begin_I2C()) { // Initialize the sensor for I²C
    Serial.println("Failed to find LIS3MDL chip");
    while (1) { delay(10); }
  }
  
  Serial.println("LIS3MDL Found!");
}

void loop() {
  lis3mdl.read(); // Get new data from the sensor
  
  Serial.print("X: "); Serial.print(lis3mdl.x); 
  Serial.print(" Y: "); Serial.print(lis3mdl.y);
  Serial.print(" Z: "); Serial.print(lis3mdl.z);
  
  Serial.println(" uT"); // Microteslas
  
  delay(500); // Wait half a second between readings
}

Troubleshooting and FAQs

Common Issues

  • Inaccurate Readings: Ensure that the sensor is calibrated correctly and that there are no nearby magnetic sources interfering with the measurements.
  • No Communication: Check the wiring, ensure that the correct I²C address or SPI settings are used, and that the library is installed properly.

FAQs

Q: Can the LIS3MDL be used for detecting metals? A: The LIS3MDL is designed to measure magnetic fields and can detect ferromagnetic materials that affect those fields, but it is not a metal detector per se.

Q: How do I calibrate the magnetometer? A: Calibration typically involves rotating the sensor in various orientations and using the collected data to offset any biases. Adafruit provides a guide and example code for calibration.

Q: What is the default I²C address of the LIS3MDL? A: The default I²C address is 0x1C, but it can be changed to 0x1E by connecting the SDO pin to the supply voltage.

For further assistance, consult the Adafruit LIS3MDL datasheet and the Adafruit support forums.