

The LSM303 Breakout Board by SparkFun Electronics is a compact sensor module that integrates a 3-axis accelerometer and a 3-axis magnetometer. This combination enables precise tilt-compensated heading and orientation detection, making it an excellent choice for navigation, motion tracking, and robotics applications. The module is designed for ease of use, with I2C communication and a small form factor suitable for embedded systems.








The LSM303 Breakout Board is based on the STMicroelectronics LSM303DLHC sensor. Below are the key technical details:
| Parameter | Value |
|---|---|
| Accelerometer Range | ±2g, ±4g, ±8g, ±16g |
| Magnetometer Range | ±1.3 to ±8.1 gauss |
| Communication Interface | I2C |
| Operating Voltage | 3.3V to 5V |
| Current Consumption | ~110 µA (accelerometer), ~100 µA (magnetometer) |
| Operating Temperature | -40°C to +85°C |
| Dimensions | 0.8" x 0.8" (20.3mm x 20.3mm) |
The breakout board has the following pin layout:
| Pin Name | Description |
|---|---|
| VIN | Power input (3.3V to 5V) |
| GND | Ground |
| SDA | I2C data line |
| SCL | I2C clock line |
| DRDY | Data ready interrupt (optional) |
| INT1 | Interrupt 1 (configurable for accelerometer) |
| INT2 | Interrupt 2 (configurable for magnetometer) |
To use the LSM303 Breakout Board with an Arduino UNO, follow these steps:
Wiring:
VIN pin to the Arduino's 5V pin.GND pin to the Arduino's GND pin.SDA pin to the Arduino's A4 pin (I2C data line).SCL pin to the Arduino's A5 pin (I2C clock line).Install Required Libraries:
Example Code: Use the following example code to read accelerometer and magnetometer data:
#include <Wire.h>
#include <SparkFunLSM303C.h>
// Create an LSM303 object
LSM303C myLSM303;
void setup() {
Serial.begin(9600); // Initialize serial communication
Wire.begin(); // Initialize I2C communication
// Initialize the LSM303 sensor
if (myLSM303.begin() == false) {
Serial.println("LSM303 not detected. Check connections.");
while (1); // Halt execution if sensor is not detected
}
Serial.println("LSM303 initialized successfully!");
}
void loop() {
// Read accelerometer data
float accelX = myLSM303.readAccelX();
float accelY = myLSM303.readAccelY();
float accelZ = myLSM303.readAccelZ();
// Read magnetometer data
float magX = myLSM303.readMagX();
float magY = myLSM303.readMagY();
float magZ = myLSM303.readMagZ();
// Print accelerometer data
Serial.print("Accel (X, Y, Z): ");
Serial.print(accelX, 2); Serial.print(", ");
Serial.print(accelY, 2); Serial.print(", ");
Serial.println(accelZ, 2);
// Print magnetometer data
Serial.print("Mag (X, Y, Z): ");
Serial.print(magX, 2); Serial.print(", ");
Serial.print(magY, 2); Serial.print(", ");
Serial.println(magZ, 2);
delay(500); // Wait 500ms before the next reading
}
Sensor Not Detected:
Inaccurate Readings:
No Data Output:
begin() function returns true.Q1: Can I use the LSM303 with a 3.3V microcontroller?
A1: Yes, the breakout board is compatible with both 3.3V and 5V systems.
Q2: How do I calibrate the magnetometer?
A2: Rotate the sensor in all directions to collect data for a full 3D calibration. Use software tools or algorithms to compute offsets and scaling factors.
Q3: What is the maximum I2C clock speed supported?
A3: The LSM303 supports I2C clock speeds up to 400kHz (Fast Mode).
Q4: Can I use the LSM303 for tilt sensing only?
A4: Yes, you can use the accelerometer independently for tilt and motion detection without using the magnetometer.