Source: https://mokxi.com/parts/qmc5883l
Updated: 2026-11-18

Part

# Compass, QMC5883L (GY-271)

The GY-271 compass most sellers ship now: the Earth’s field on three axes over I2C at 0x0D, turned by a heading slider, for QMC5883LCompass.h.

See every part

- 5 pins
- 3 settings
- In 1 project

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

At a glance

## The Compass, QMC5883L (GY-271) in brief

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

The QMC5883L is a three-axis magnetometer made by QST. It sits on most GY-271 compass boards sold today and talks over I2C at address 0x0D. Flat on a bench it reads the Earth's field, and atan2 of the two horizontal readings gives the heading, which is what a compass sketch does. Boards sold as GY-271 once carried the Honeywell HMC5883L, which has a different address and register map, so a sketch written for the other chip finds nothing. Mokxi models the chip's registers, including control register 1, the status register and the six data bytes read in one block. It does not model noise, offsets, nearby magnets or the temperature offset. The sliders set heading, pitch and roll, so you can turn and tip the board while a sketch runs.

Family

Sensors

Pins

5

pitch

0

roll

0

heading

0

Pins

## 5 pins

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

Pin

What it does

VCC

Supply, 3 to 5 V on the board, which has its own 3.3 V regulator.

GND

Ground.

SCL

I2C, up to 400 kHz. The board carries the pull-ups.

SDA

I2C, up to 400 kHz. The board carries the pull-ups.

DRDY

High while a new sample waits; reading the data takes it low.

How to use it

## How to use the QMC5883L compass (GY-271) with an Arduino

The example project wires a QMC5883L compass on a GY-271 board to an Arduino Uno. The board measures the magnetic field along X, Y and Z. The sketch prints the azimuth in degrees and the compass point four times a second.

With the default settings, the serial monitor shows: "GY-271 compass at 0x0D", then "azimuth 0 N", then "azimuth 60 NE". The heading slider starts at 0, so the first reading is north.

Change the heading setting to 180 and run again. The serial monitor shows: "GY-271 compass at 0x0D", then "azimuth 0 N", then "azimuth 180 S". The board now faces south, so the azimuth follows it.

Try the pitch slider too. Tipping the board makes the heading drift, because the flat readings pick up part of the field's downward pull. That is why phones use an accelerometer to correct their compass.

Part pin

Goes to

SCL

Arduino Uno R3 pin SCL

SDA

Arduino Uno R3 pin SDA

GND

Arduino Uno R3 pin GND

VCC

5 V

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

sketch.ino · Arduino Uno R3

Common errors

## Common Compass, QMC5883L (GY-271) errors and fixes

What goes wrong

The fix

The sketch reads zeros from the compass.

The chip powers up in standby. Write continuous mode to control register 0x09, or call compass.init() from the library.

The heading jumps or sits still after some readings.

Read all six data registers in one block from 0x00. Reading only some of them locks the registers until 0x05 is read.

The sketch finds no device at all.

Your board may carry the older HMC5883L chip instead. Run an I2C scanner: 0x0D is a QMC5883L, 0x1E is an HMC5883L, and each needs its own library.

The heading is off by tens of degrees from a map.

Magnetic north is not true north. Set the declination for your town and calibrate away the board's own offsets.

Questions

## Questions and answers

### What is a GY-271 compass module?

It is a small board with a QMC5883L three-axis magnetometer. It measures the magnetic field and lets a sketch work out its heading.

### How do I connect the QMC5883L to an Arduino?

Wire VCC to 5 V, GND to GND, SCL to SCL and SDA to SDA. The board has its own regulator and I2C pull-ups.

### What does getAzimuth() return?

It returns an angle from -180 to 180 degrees. It is 0 when the board's X arrow points north.

### Can I change where the compass points in the simulator?

Yes. Drag the heading, pitch and roll sliders while the sketch runs. Pitch and roll tip the board, which makes the heading drift.

How it is modeled

## What is true about the Compass, QMC5883L (GY-271), here

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

### Not modeled

Noise, offsets, the oversampling filter and the SET/RESET period's effect (both are
stored and read back), nearby magnets and the hard iron of a robot chassis. The
temperature registers' offset is not calibrated on the real chip, only their 100 counts a
degree, so the model reads 0 and holds still.

From QMC5883L compass (GY-271), in full.

Projects

## See the Compass, QMC5883L (GY-271) 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 Compass, QMC5883L (GY-271) in it.

- Arduino Uno R3

Keep going

## Keep going

- I2C Scanner for Arduino and ESP32, and Fixes
- Compass, HMC5883L (GY-271)
- 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 Compass, QMC5883L (GY-271)

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
