Source: https://mokxi.com/parts/lsm303agr
Updated: 2026-11-19

Part

# Accelerometer and compass, LSM303AGR

An accelerometer at 0x19 and a magnetometer at 0x1E in one package: a tilt-compensated compass.

See every part

- 6 pins
- 3 settings
- In 1 project

Drawn live by the editor's own code, at the size you see it.

At a glance

## The Accelerometer and compass, LSM303AGR in brief

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

The LSM303AGR puts an accelerometer at 0x19 and a magnetometer at 0x1E in one package: the two halves of a tilt-compensated compass. The accelerometer says which way is down, the magnetometer which way is north, and together they give a heading that stays right when the board tips. VIN and GND take 3 V to 5 V on the board, SCL and SDA are I2C with both halves on the same bus and the pull-ups on the board, and INT1 and INT2 are interrupts left high-impedance by the model. The heading, pitch and roll properties are how the board sits, and the sliders turn and tip it. Aliases include the LSM303DLHC and the Adafruit LSM303AGR.

Family

Sensors

Pins

6

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, both halves on the same bus. The board carries the pull-ups.

SDA

I2C, both halves on the same bus. The board carries the pull-ups.

INT1

Interrupts, left high-Z by the model.

INT2

Interrupts, left high-Z by the model.

How to use it

## How to read an LSM303AGR compass and accelerometer with an Arduino

The compass’s SDA and SCL go to the Uno’s SDA and SCL, with VIN on 5 V and GND on GND. Both halves share the bus: the accelerometer is at 0x19 and the magnetometer at 0x1E. An LTR-390 UV sensor shares the same I2C wires, on A4 and A5. The sketch includes Adafruit_LSM303_Accel and Adafruit_LTR390.

The compass heading comes from the magnetometer’s two level axes, so it is only right while the board is flat; the accelerometer says how far it is tipped. A UV index of 3 or more wants sunscreen, and the project warns there. Drag the heading slider round, tip the board with the roll slider and drag the UV slider past 3.

Part pin

Board pin

VIN

5 V

GND

GND

SDA

SDA

SCL

SCL

INT1, INT2

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.

Click to open it in the editor

This is the simulator itself, running here. Click anything to open it in the editor.

Open this project in the editor Read the full tutorial

Common errors

## Common Accelerometer and compass, LSM303AGR errors and fixes

What goes wrong

The fix

The heading is wrong when the board is tilted.

The magnetometer’s level axes are only right while the board is flat. Use the accelerometer’s pitch and roll to correct it.

Only one half answers.

They have two addresses: 0x19 for the accelerometer and 0x1E for the magnetometer. Scan the bus and use both.

The heading is off by a fixed angle.

It is relative to magnetic north, and anything magnetic nearby bends it. Keep the sensor away from motors and magnets.

Questions

## Questions and answers

### What are the I2C addresses of the LSM303AGR?

0x19 for the accelerometer and 0x1E for the magnetometer, on the same bus.

### What is a tilt-compensated compass?

One where the accelerometer says which way is down and the magnetometer which way is north, so the heading stays right when the board tips.

### Why does the heading need the board flat?

The simple heading uses only the magnetometer’s two level axes. The accelerometer says how far it is tipped, to correct for it.

How it is modeled

## What is true about the Accelerometer and compass, LSM303AGR, here

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

### Not modeled

The FIFO, the click and interrupt engines, the temperature sensor, hard-iron offsets,
and noise.

From LSM303AGR accelerometer and compass, in full.

Projects

## See the Accelerometer and compass, LSM303AGR 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 Accelerometer and compass, LSM303AGR in it.

- Arduino Uno R3

Keep going

## Keep going

- I2C Scanner for Arduino and ESP32, and Fixes
- Arduino MPU6050: Accelerometer and Tilt
- Accelerometer and gyroscope, MPU6050
- Nine-axis IMU, MPU-9250
- Magnetometer, LIS3MDL

More parts

## The rest of the bench

Every one of these is drawn and simulated the same way.

Full-size breadboard

A real 0.1 inch grid with the rails and the center channel, 63 columns wide.

Jumper wires

Drag from any pin or hole to any other. Corners snap, and you can drag them.

Power

A supply rail at the voltage you choose.

Ground

The other end of every circuit.

LED

Lights when current flows. Five colors, and the brightness is what your eye would see.

Filament lamp

A tungsten bulb in a holder: an inrush when it is switched on cold, tens of milliseconds to warm up, and dim on half its voltage.

Resistor

Any value you like, with the color bands drawn to match.

ESP32-C3-DevKitM-1

A RISC-V board that runs your firmware at 160 MHz on the real memory map.

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

Raspberry Pi Pico

The RP2040 board on our own Cortex-M0+ core. Pick a program and press Run.

Raspberry Pi Pico W

Raspberry Pi Pico W (RP2040). The same board and the same pinout as a Pico, with the CYW43439 on it. The WiFi is simulated (no radio; real internet through the Cloud panel’s switch), and the on-board LED, which hangs off that chip rather than off GP25, is driven through the same path. Everything else is the Pico.

Raspberry Pi 4 Model B

Raspberry Pi 4 Model B: the 40-pin header, driven by main.py with RPi.GPIO or gpiozero.

See every part

## Wire up the Accelerometer and compass, LSM303AGR

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

Start building free Open the editor
