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:
Table of Contents
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)
- AliExpress: https://s.click.aliexpress.com/e/_DCihHmP
- GetFPV: https://oscarliang.com/product-zixk
Top Performer: HGLRC M100 5883 (With Compass)
- AliExpress: https://s.click.aliexpress.com/e/_DlLhgFd
- GetFPV: https://oscarliang.com/product-bf3p
- RDQ: https://oscarliang.com/product-0yby
Smallest Worth Having: GOKU GM10 Nano V3 (With Compass)
- AliExpress: https://s.click.aliexpress.com/e/_DEqdlNV
- Flywoo: https://oscarliang.com/product-lfo7
- GetFPV: https://oscarliang.com/product-tort
- RDQ: https://oscarliang.com/product-plki
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.
Download and install iNav Configurator here: https://github.com/iNavFlight/inav-configurator/releases
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 = custom
set mag_align_roll = X
set mag_align_pitch = Y
set mag_align_yaw = Z
save
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 (e.g. for 11.4, enter 114; for 2.5, enter 25 and so on):
set mag_declination = 114
save
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.
12 comments
There’s an error in the post, set mag_declination is specified as an integer in decidegrees, so
set mag_declination = 11.4
should have been
set mag_declination = 114
Setting 11.4 in cli results in 11 being saved and showing up as 1.1 in the configuration tab. Entering 11.4 in the configuration tab correctly saves mag_declinatgion as 114
Thanks, it was a typo i overlooked. Corrected now.
Good afternoon, first of all thank you for your work. Could you please explain how exactly you determined that the compass is faulty?
I’m a beginner, and magnetometer configuration is driving me crazy. According to all the indicators from the article, the value should be CW270FLIP, but it doesn’t work and the compass shows an incorrect heading. When I rotate the drone on the yaw axis, the compass seems to rotate with it (even though it shows incorrect values), but as soon as I stop, it seems to jump back to the initial value (for example, northeast).
According to your cheat sheet, this should be CW270FLIP. In INAV, I’m getting the following values:
`align_mag_roll = 0`, `align_mag_pitch = 1800`, `align_mag_yaw = 2700` (which matches how the compass is physically mounted on the drone), and these values also seem to correspond to CW270FLIP.
I also checked the status in Betaflight, and the magnetometer is detected there. The module is mounted flat, not at an angle.
Could you please advise what I might be doing wrong? I’m using a BLITZ Mini M10 GPS V2, mounted above the camera on an iFlight Chimera 7 Pro V2 (so it shouldn’t be affected by the battery, although I also tried moving the battery as far away as possible). The module is installed with the GPS antenna facing upward (pins facing downward), and the pins are oriented forward in the direction of flight.
I would really appreciate your help.
Make sure the magnetometer is as far away from any interference (e.g. wires and motors) as possible.
it’s also possible that you have a faulty magnetometer, which is not uncommon. 1 in 3 GPS I’ve tested has a wonky magnetometer.
I tried to maintain a 12-inch distance between the GPS and the battery by holding it in my other hand, separate from the drone, to avoid interference. Could you advise if there’s a way to confirm that the magnetometer is faulty? Or is the only way to verify this to purchase another module and hope it isn’t defective and that the same configuration will work?
Not sure why, but In the Configuration tab the Magnetometer Alignment box doesn’t show up for me. I downloaded the betaflight Version and the offline Betaflight configurator last week, so should be the newest version each.
I have an older Laptop running Mint Linux (wanted to use it as a dedicated Laptop for all FPV stuff that i can take with me when i go flying)
Any suggestions what i am doing wrong?
Did you flash Betaflight with magnetometer feature included in the build option?
https://oscarliang.com/betaflight-position-hold/#Update-Betaflight
I thought I did include it, but maybe i forgot, it was late in the evening when i flashed it.
I will double check it or better flash it again to be sure. Thanks a lot for the quick reply!
Before re-flashing the firmware, you can check your current build options to see if it’s included: https://oscarliang.com/check-betaflight-build-options/
Magnetometer seems to be icluded in the build options.
To be sure I flashed again. still no Magnetometer Alignment box to be found.
This is what the build key put out:
“release”: “2025.12.2”,
“target”: “MATEKF405CTR”,
“commit”: “2025.12.2”,
“options”: [
“CLOUD_BUILD”,
“USE_ALTITUDE_HOLD”,
“USE_DSHOT”,
“USE_GPS”,
“USE_GPS_PLUS_CODES”,
“USE_LED_STRIP”,
“USE_MAG”,
“USE_OSD”,
“USE_OSD_SD”,
“USE_PINIO”,
“USE_POSITION_HOLD”,
“USE_SERIALRX”,
“USE_SERIALRX_SBUS”,
“USE_SOFTSERIAL”,
“USE_TELEMETRY”,
“USE_TELEMETRY_SMARTPORT”,
“USE_VTX”
],
Is Magnetometer enabled in the Configuration tab?
If you go to CLI, and type Status, does “MAG” say a specific name, or just none? https://oscarliang.com/betaflight-cli-explained/#status-%E2%80%93-Check-FC-System-Info
If it says none then it means it didn’t detect any magnetometer.
OK… i found the problem.
There was no MAG in the Status, but an I2C Error. so i googeld and foun nothing. then I looked at the documentation of the FC… the LED Strip uses the same I2C as the Mag and Baro, i can choose between Mag & Baro or LED_Strip.
now I falshed again without LED_strip, followed your guide and now it works… except for the declination… this didnt show up. but thats a problem for the next days.
FC was a Matek F405-CTR btw.
Thanks a lot for your help!