A magnetometer (also known as a compass) can be very useful for GPS Rescue and Position Hold in Betaflight, as it improves accuracy and overall performance. However, it can also be quite complex to set up and calibrate correctly. If a magnetometer is misconfigured or poorly calibrated, it can actually make things worse—causing drifting, incorrect heading, or even flyaways.
In this guide, I’ll walk you through magnetometer orientation, declination, calibration, and verification step by step to make the process easier to understand.
Disclaimer: This guide reflects how I personally set up and calibrate a magnetometer. I am not responsible for any damage resulting from following these instructions. Please refer to Betaflight’s official documentation for details: https://www.betaflight.com/docs/wiki/guides/current/magnetometer
Check out my tutorials on:
What Is a Magnetometer (and Why It Matters)
The magnetometer tells the flight controller which direction the quad is facing. This information helps the drone to:
- Maintain heading in Position Hold mode
- Improve GPS Rescue mode accuracy
- Reduce yaw drift during GPS-assisted flight modes
Some GPS modules have a built-in magnetometer.
GPS Recommendations
See my GPS testing here: https://oscarliang.com/gps-review/
Top Performer: GEPRC M1025Q (With Compass)
Top Performer: HGLRC M100 5883 (With Compass)
Smallest Worth Having: GOKU GM10 Nano V3 (With Compass)
How to Connect Magnetometer to Flight Controller
If your GPS module includes a compass, it should have two additional pads: SCL and SDA. These are for the I2C bus used by the magnetometer.
Wiring is easy:
- SDA (GPS) → SDA (FC)
- SCL (GPS) → SCL (FC)
Where to Mount Magnetometer
You should keep the compass as far away as possible from sources of electromagnetic interference, including:
- ESC
- Motors
- Motor wires
- Power cables (e.g. XT60)
- Action cameras
Good locations for mounting a GPS module include:
- Above the FPV camera
- At the rear of the drone (as long as it’s not too close to the VTX antennas)
- On the battery strap
For small quadcopters (e.g. under 5-inch), it’s harder to get clean compass readings simply because everything is packed so closely together.
Betaflight Setup
In Betaflight Configurator:
- Go to Configuration → System Configuration
- Enable Magnetometer
- Save and reboot
After rebooting, the magnetometer icon (Mag) at the top of the configurator should light up. If it doesn’t, check power and wiring.
Identify Magnetometer Chip
Open the CLI and type:
status
This confirms whether the magnetometer is detected and also helps identify the chip. Common magnetometer chips used in GPS modules include HMC5883 and QMC5883.
Understanding Magnetometer Orientation
Just like a gyro, a magnetometer has three axes: X, Y, and Z. However, these axes are defined by the orientation of the magnetometer chip itself, not how it’s mounted in the drone.
On your GPS module, look for a small dot on the magnetometer chip—this marks pin 1.
Google the chip’s datasheet online. It should include a diagram showing how the X, Y, and Z axes are oriented relative to the chip and the small dot. For the QMC5883 magnetometer I am using:
- X-axis points down
- Y-axis points right
- Z-axis points up
Betaflight expects the magnetometer to be oriented like this:
- X-axis → pointing forward
- Y-axis → pointing left
- Z-axis → pointing up
Depending on how you mount your GPS module, you may need to adjust the magnetometer alignment in Betaflight settings.
Why Alignment Is Often Needed
If you mount the magnetometer perfectly parallel to the flight controller, setup would be simple. However, on most GPS modules the magnetometer is located on the opposite side of the GPS antenna. And since the GPS antenna must face the sky, the magnetometer usually ends up being upside down, which means alignment changes are usually inevitable.
If this is your first time using a compass, keep things simple:
- Mount the GPS flat and level relative to the frame and FC
- Avoid angled or tilted mounts
- Get it working first before attempting custom alignment
In my setup, I kept things simple by mounting the GPS at the front of the quad, level with the frame and FC (using double-sided tape and zip tie).
Because the compass is simply flipped over on the pitch axis, I selected “CW 0° Flip” under Magnetometer Alignment in Betaflight.
Here’s a handy cheat sheet you can use for common compass alignments.
Custom Alignment (Advanced)
If you are using a GPS mount with a tilt angle, then Custom Alignment is required. This can be confusing for beginners, which is why I strongly recommend mounting the GPS flat if possible so you don’t have to deal with this 🙂
That said, the Alignment Tool in iNav Configurator is extremely helpful—even if you don’t use iNav.
How to use it:
- Open iNav Configurator
- Enter Demo Mode (so you can connect without a FC)
- Go to Alignment Tool
- Select X, Y, Z (more reliable than picking magnetometer)
- Adjust the X, Y, Z sliders until they match your magnetometer’s physical orientation
- Take note of the final Roll (X), Pitch (Y), and Yaw (Z) values
Now go back to Betaflight:
- In the Configuration tab, select Custom under Magnetometer Alignment
- Enter the Roll, Pitch, and Yaw values
Alternatively, you can do this via the CLI:
set align_mag = customset mag_align_roll = Xset mag_align_pitch = Yset mag_align_yaw = Zsave
Set Magnetic Declination
Magnetic north is not the same as true north, and Betaflight needs your local magnetic declination value to correct this difference.
Declination varies by location. You can find it using a trusted website such as: https://www.magnetic-declination.com/
Example:
- For Los Angeles, USA, the magnetic declination is +11° 24′.
- Convert this to decimal (Google can do this for you): 11.4°
Enter this value in the Configuration tab
Or enter it in CLI:
set mag_declination = 11.4save
Calibrate Magnetometer
Ideally, you should perform compass calibration at the location where you plan to fly. Stay well away from anything that could cause magnetic interference, such as:
- Metal objects
- Cars
- Power lines
- Reinforced concrete
You can initiate calibration either by clicking the Calibrate Magnetometer button in Betaflight Configurator (setup tab), or by using stick commands. I personally prefer stick commands, as it allows me to unplug the USB cable and rotate the quad freely.
How to Calibrate Magnetometer
- Remove propellers and power up the quad
- Initiate calibration using the stick command:
- Pitch down + yaw up-right → you should hear 2 beeps
- Spin the quad quickly to start calibration
- You will hear 7 fast beeps indicating calibration has begun
- You now have 30 seconds to complete calibration
- The quad will make 3 beeps when calibration is complete
If your quad does not have a beeper, you can look at the FC LED instead:
- Solid LED = calibration in progress
- Normal blinking = calibration completed
How to Move the Quad During Calibration
During the 30-second calibration window:
- Hold the quad by the battery
- Swing your arm in a figure-8 pattern
- At the same time, yaw the quad left and right randomly
- Slowly turn your entire body by taking small steps. By the end of the calibration, you should have completed roughly a full 360° rotation.
Compass calibration usually only needs to be done once within your local area. However, if you travel far away from home, it’s a good idea to recalibrate.
Validate Heading
After calibration, verify the heading carefully:
- Use the Betaflight Configurator home screen or
- Enable the Compass Bar in the OSD
Compare the heading against a smartphone compass app. Make sure the app is set to true heading, not magnetic heading.
Test by facing different directions:
- Face north → should read north
- Rotate east, south, and west → verify accuracy
If the Heading Is Incorrect
If the heading is clearly wrong:
- Recheck compass orientation
- Try different Mag Alignment options in Configurator (CW0 / CW90 / CW180 / CW270)
- Redo calibration in a clean environment
- Re-test after every change
In some cases, the compass itself may be faulty. I tested 3 different GPS modules and found that one had a faulty compass—so this is not uncommon.
Final Thoughts
You can fly Betaflight without a magnetometer—but if you want reliable Position Hold and accurate GPS Rescue, a properly configured and calibrated magnetometer can make a difference. Once it’s set up correctly, you rarely need to touch it again unless you change hardware or GPS placement. And don’t forget to recalibrate if you fly far away from your usual location.

