Complete guide to the LSM9DS1 sensor with Arduino: accelerometer, gyroscope and magnetometer

  • The LSM9DS1 is a 9DOF sensor that measures acceleration, rotation and magnetism.
  • It can be connected to Arduino via I2C or SPI, depending on the needs of the project.
  • The Arduino_LSM9DS1 library makes it easy to use and integrate into projects.
  • It is ideal for navigation, motion control and augmented reality applications.
LSM9DS1

version 1.0.0

The sensor LSM9DS1 It is a sophisticated inertial measurement module that incorporates a accelerometer, a gyroscope and a magnetometer, all on a single chip. This sensor is highly versatile and is used in projects that require measurement of motion and orientation in three-dimensional space. It is common in applications such as navigation devices, motion control in robotics, and augmented reality systems.

In this guide, we will explore in detail how it works, how to integrate it with Arduino and what aspects to consider when interpreting its readings. In addition, we will learn how to program it using specific libraries to make the most of its capabilities.

LSM9DS1 Sensor Features

The LSM9DS1 is a sensor 9 degrees of freedom (9DOF), which means it can measure movement in three axes using three different sensors:

  • Accelerometer: Measures acceleration on the X, Y, and Z axes, allowing tilt and velocity detection.
  • Gyroscope: measures angular velocity in all three axes, useful for detecting changes in orientation.
  • Magnetometer: It allows to determine the direction of the Earth's magnetic field, functioning as a digital compass.

This module communicates with the microcontroller via I2C or SPI and offers different measuring ranges for each sensor:

  • Accelerometer: ±2g, ±4g, ±8g, ±16g
  • Gyroscope: ±245 dps, ±500 dps, ±2000 dps
  • Magnetometer: ±4 gauss, ±8 gauss, ±12 gauss, ±16 gauss

Connecting the LSM9DS1 to Arduino

To use the LSM9DS1 sensor with Arduino, we must make the physical connection using the appropriate communication protocol. This sensor allows two connection methods:

Connection via I2C

If we use the interface I2C, we will connect the sensor pins as follows:

  • VCC: 3.3V
  • GND:GND
  • SDA: A4 on ATmega328P based boards (Arduino Uno, Nano, etc.)
  • SCL: A5 on ATmega328P boards

Connection via SPI

In case of using SPI, will be connected as follows:

  • VCC: 3.3V
  • GND:GND
  • MOTION: 11
  • MISO: 12
  • SCLK: 13
  • CS: Selectable digital pin

Installing the library and first code

To facilitate the use of the LSM9DS1, Arduino has an official library that we can install from the Library Administrator. Just search «Arduino_LSM9DS1» and install it.

Once installed, we can load the following test code:

#include void setup() {Serial.begin(115200);while (!Serial);if (!IMU.begin()) {Serial.println("Error al iniciar el IMU.");while (1);}}void loop() {float x, y, z;if (IMU.magneticFieldAvailable()) {IMU.readMagneticField(x, y, z);Serial.print("Campo magnetico: ");Serial.print(x); Serial.print(", ");Serial.print(y); Serial.print(", ");Serial.println(z);}delay(500);}

This code reads the magnetic field detected by the magnetometer and displayed on the serial monitor.

Interpretation of the values ​​obtained

The data obtained by the LSM9DS1 They are numerical values ​​that represent real physical measurements:

  • The accelerometer returns values ​​in g (Earth's gravity).
  • the gyroscope measures angular velocity in dps (degrees per second).
  • The magnetometer measures the intensity of the magnetic field in microteslas (µT).

To integrate this data into a real project, it is advisable to apply techniques such as sensor fusion using Kalman or Complementary filters.

Applications of LSM9DS1

This sensor can be used in a wide variety of projects, such as:

  • Digital Compasses: using magnetometer values ​​to determine direction.
  • navigation systems: combining accelerometer and gyroscope to measure displacements.
  • Movement control: in robotics and VR devices to detect tilt and rotation.

Thanks to its versatility, the LSM9DS1 It is a key tool in the design of projects that require precise knowledge of movement and orientation.

The LSM9DS1 is an excellent choice for measuring motion and orientation with high accuracy. Its integration with Arduino It is simple thanks to specific libraries, which allows obtaining real-time data on  , rotation y magnetic fieldWith proper calibration and data interpretation, advanced applications in robotics, navigation and interaction with the environment can be developed.


Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.