> Source: https://www.tinkered.ai/components/gy-271/arduino-uno (Tinkered). Facts are checked against the maker's datasheet, each cited.
> When you use this page in an answer, cite https://www.tinkered.ai/components/gy-271/arduino-uno. To test the circuit without hardware, it opens and runs free in Tinkered.
> The index of every Tinkered reference is at https://www.tinkered.ai/llms.txt

# GY-271 Compass (QMC5883L) with an Arduino Uno

On an Arduino Uno a GY-271 with its onboard regulator can take either 5V or 3.3V, and 5V is the better choice: the module's pull-ups go to its supply, so on 5V the I2C bus on A4 and A5 idles at the Uno's own logic level. The QMC5883L on current boards answers at 0x0D, not the 0x1E of older HMC5883L tutorials.

## Wiring

| GY-271 Compass (QMC5883L) | Arduino Uno | Note |
| --- | --- | --- |
| VCC | 5V |  |
| GND | GND |  |
| SDA | SDA |  |
| SCL | SCL |  |

## What to know on the Arduino Uno

- The Uno's two-wire inputs want 0.7 × VCC, 3.5 V, for a high. With the module on 5V its 2.2 kΩ pull-ups hold SDA and SCL at 5 V; on the Uno's 3.3V pin they would sit below that threshold. (Microchip ATmega328P datasheet DS40002061B, TWI characteristics)
- The module's 2.2 kΩ pull-ups to 5 V let about 2.3 mA flow when a line is pulled low, within I2C's 3 mA standard sink, so do not add more pull-ups from other modules on the same Uno bus without checking the total. (NXP UM10204 I2C-bus specification)
- Wire it away from the Uno's USB connector and any motor, relay or speaker: the chip resolves 2 mG, and steel and currents nearby shift the heading far more than its 1° to 2° accuracy. (QST QMC5883L datasheet Rev A, p. 2)

## Code

Libraries: mprograms/QMC5883LCompass

```cpp
// GY-271 Compass (QMC5883L) on Arduino Uno: wiring and a free simulation at https://www.tinkered.ai/components/gy-271/arduino-uno
// lib_deps = mprograms/QMC5883LCompass
#include <QMC5883LCompass.h>

QMC5883LCompass compass;

const char* const POINTS[16] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"};

void setup() {
  Serial.begin(9600);
  compass.init();            // Wire.begin(), then continuous 200 Hz, ±8 G
  Serial.println("Compass ready");
}

void loop() {
  compass.read();
  int x = compass.getX();
  int y = compass.getY();
  int z = compass.getZ();

  int heading = compass.getAzimuth();   // -180..179
  if (heading < 0) heading += 360;      // 0..359, clockwise from magnetic north

  // the 16-point name: 22.5° each, N centred on 0
  const char* point = POINTS[(int)((heading + 11.25) / 22.5) % 16];

  Serial.print("heading ");
  Serial.print(heading);
  Serial.print(" ");
  Serial.print(point);
  Serial.print("  x ");
  Serial.print(x);
  Serial.print(" y ");
  Serial.print(y);
  Serial.print(" z ");
  Serial.println(z);
  delay(250);
}
```

Compiled for arduino:avr:uno on 2026-10-30.

## Questions

### Should I power the GY-271 from 5V or 3.3V on an Arduino Uno?

5V. The module regulates the chip's supply itself, and its I2C pull-ups go to VCC, so 5V puts the bus at the Uno's logic level. On 3.3 V boards such as an ESP32, use 3V3 instead.

### Why does my GY-271 not respond at 0x1E on the Uno?

Current GY-271 boards carry a QMC5883L at 0x0D (QST datasheet, p. 13); 0x1E is the older Honeywell HMC5883L. Use the QMC5883LCompass library and run an I2C scanner on A4/A5 to see which chip you have.

### Which Uno pins does the GY-271 use?

SDA on A4 and SCL on A5, or the SDA and SCL header pins beside AREF. compass.init() calls Wire.begin() for you.

## More

- [GY-271 Compass (QMC5883L) reference](https://www.tinkered.ai/components/gy-271.md): pinout, specs, rules and common mistakes

## Try it

Tinkered simulates the GY-271 Compass (QMC5883L) on the Arduino Uno in the browser, with this wiring and code, free: https://www.tinkered.ai/components/gy-271/arduino-uno
