# SparkFun Forums

### Orientation from magnetometer data

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!

### Orientation from magnetometer data#200535

#200535
Dear Experts!

I saw lot of topics with the same title but answers are different.
I have a magnetometer in my phone which give me the components of magnetic field in direction of X, Y, Z.

Which of the following angles can be determined using datas of magnetometer? Roll, pitch, yaw? And how?

Thank you, Robert

### Re: Orientation from magnetometer data#200547

By jremington
#200547
yaw_angle=atan2(magy,magx); //if magnetometer is held level, with Z straight up or down. angle in radians to magnetic North.

It is essential to calibrate the magnetometer, as described here: https://thecavepearlproject.org/2015/05 ... r-arduino/

### Re: Orientation from magnetometer data#200548

#200548
jremington wrote: Tue Oct 02, 2018 10:02 am yaw_angle=atan2(magy,magx); //if magnetometer is held level, with Z straight up or down. angle in radians to magnetic North.

It is essential to calibrate the magnetometer, as described here: https://thecavepearlproject.org/2015/05 ... r-arduino/
Dear Jremington!

Thank you for your reply. Estimation of roll and yaw angle is impossible just from the magnetometer?

### Re: Orientation from magnetometer data#200549

By jremington
#200549
The magnetometer makes three measurements, so you can get two 3D orientation angles, related to the local magnetic field direction (which points into the ground in the Northern hemisphere). Yaw can be one of the angles. What you call the other is up to you.

Using the same method, you can get standard pitch and roll angles from an accelerometer, as described here: https://www.dfrobot.com/wiki/index.php/ ... lt_Sensing