GY-271 Compass tilt compensation idea

Hi My first time posting but I see the standard method in using GT-271 board for compass application is to
keep it level and read the x and y values. I had a simple idea that instead of tilt compensation can't one read the z axis when it is level and use that approximate value to only take valid readings ie:when z value is close to your level z value. I have not put my idea into practice but in the back of my mind I suspect it has a flaw in the logic. I assume the motion of my sensor will pass through the level stage once every couple of seconds.This will give me more than enough readings to keep a course. Faulty logic or possible?

The mag_z value reports the projection of the Earth's magnetic field vector onto the magnetometer Z-axis, and any rotation of the compass about the Earth's magnetic field vector would give the same result. But perhaps you can exclude most of the wrong orientations.

You can always try and see if it works. That is the beauty of Arduino!

A bubble level works well.

]Thanks for the reply. I will give it a wack and look at the results . My view point was if I keep the z a constant , the changes in x and y will be my direction in 2D plane . I will try it this evening .

The issue I ran into with calibrating a magnetometer is that once the device is moved, the calibration is no longer valid.

I ordered several magnetometers. In a near same position, I plugged them in, took x,y,z readings and found 2 that read fairly close to each other. I mounted the 2 magnetometers so that each magnetometer axis is 180 degrees out of phase with each other, and programmatically, summed the readings together for a self calibrating magnetometer that self calibrates as the device is moved.