QMC6309 3-Axis Electronic Compass with I²C interface, high stability, and built-in self-test. Perfect for drones, robotics, and navigation.
The QMC6309, produced by QST Corporation, is a compact and energy-efficient digital magnetometer designed to detect magnetic fields across three axes (X, Y, Z). It integrates both magnetic sensing elements and signal-conditioning circuitry into a single silicon chip.The QMC6309 stands out as a diminutive, energy-efficient, and accurate 3-axis magnetometer solution, ideal for compact and embedded electronics like VR trackers and flight controllers. With its seamless integration of sensing and signal conditioning, it provides high-precision magnetic field data with minimal PCB footprint.
Pin Configuration
VCC : Power supply
GND : Ground connection
SDA : SDA of GLYPH board
SCL : SCL of GLYPH board
Key Features
3-axis magnetic field sensing (X, Y, Z)
I²C digital interface for easy MCU integration
16-bit ADC resolution for high-precision measurements
Wide supply voltage range: 2.5 V – 3.6 V
Low operating current: ~2 mA (ideal for battery-powered devices)
Designed for consumer electronics like VR trackers, wearables, and flight controllers
Applications
VR / AR Trackers – orientation tracking and drift correction
Robotics & Drones – navigation, stabilization, and position control
Flight Controllers – magnetic heading reference in UAVs and quadcopters
Research & Education – low-cost magnetometer for embedded learning projects
QMC6309 Simple Example
Step 1: Hardware Required
Glyph Boards
QMC6309
Step 2: Circuit Diagram
Step 3: Code Setup
Open Arduino IDE.
Make sure to install the library
Copy and paste the following code into the Arduino IDE:
Step 4: Upload the Code
//You can download the PCBCUPID_QMC6309 library from here : https://github.com/pcbcupid/PCBCUPID-QMC6309#include <Wire.h>#include "PCBCUPID_QMC6309.h"#include "ExponentialFilter.h"PCBCUPID_QMC6309 mag(Wire);// Calibrated offsetsconst float x_offset = 3485.0;const float y_offset = 1290.0;const float declination = 0.22;// Filter object: 0.2 weight (20%)ExponentialFilter headingFilter(0.2, 0.0);void setup() { Serial.begin(115200); delay(1000); if (!mag.begin()) { Serial.println("Magnetometer init failed"); while (1); } Serial.println("Heading with Exponential Filter");}void loop() { int16_t x, y, z; if (mag.readRaw(x, y, z)) { float x_cal = x - x_offset; float y_cal = y - y_offset; float heading = atan2(-x_cal, y_cal) + declination; if (heading < 0) heading += 2 * PI; if (heading > 2 * PI) heading -= 2 * PI; float headingDeg = heading * 180.0 / PI; // Apply exponential filter headingFilter.update(headingDeg); float smoothedHeading = headingFilter.get(); Serial.print("Heading: "); Serial.print(smoothedHeading, 1); Serial.print("° ("); Serial.print(mag.headingToDirection(smoothedHeading)); Serial.println(")"); } delay(200);}
Connect the Board
Connect your GLYPH board to your computer
Select the Board and Port
Do the following settings in your Arduino IDE,
Tools > Board > esp32 > Pcbcupid GLYPH C3
For the Pcbcupid Glyph C3 to appear under Tools > Board > esp32, the esp32 board version installed in the Arduino IDE should be greater or equal to 3.1.0.
Tools > Port and select the port connected to your GLYPH.
Tools > USB CDC on Boot >Enabled
If USB CDC on BOOT not enabled, you won’t be seeing any serial data on Arduino IDE.
Upload the Code
Click the upload button (➡️ icon) or use the shortcut CRTL + U in Arduino IDE to upload the code to the board.
Step 5: Observe the Output
The output shows the smoothed compass heading in degrees (0–360°) along with its cardinal direction (e.g., N, NE, E, SE, etc.).
Might not have accurate reading as this was not the intended purpose, This module is very useful to find strong magnetic field in 3 dimensional space.
QMC6309 with oled
Step 1: Hardware Required
Glyph Boards
QMC6309
OLED Display
Step 2: Circuit Diagram
Step 3: Code Setup
Open Arduino IDE.
Make sure to install the “Audio Tool” library
Copy and paste the following code into the Arduino IDE:
For the Pcbcupid Glyph C3 to appear under Tools > Board > esp32, the esp32 board version installed in the Arduino IDE should be greater or equal to 3.1.0.
Tools > Port and select the port connected to your GLYPH.
Tools > USB CDC on Boot >Enabled
If USB CDC on BOOT not enabled, you won’t be seeing any serial data on Arduino IDE.
Upload the Code
Click the upload button (➡️ icon) or use the shortcut CRTL + U in Arduino IDE to upload the code to the board.
Step 5: Observe the Output
outputs real-time X, Y, Z magnetometer readings as both serial text and dynamic bar graphs on an OLED, showing deviation from running average with percentage values.