I have a sensor tag from Texas and have been able to communicate with it over BLE and get magnetometer readings using a node.js library.

However I am tough time going from the x,y,z mag. axis readings to being able to say NORTH, SOUTH, EAST, WEST. Any pointers in the direction would be of great help.

Thanks. :)


1 Answer 1


Determine which axis of the device is going to point North. That is your north unit vector. Convert the x, y, and z magnetometer data to a vector. From there, use the dot product. \$cos\theta=\dfrac{A\cdot B}{|A||B|}\$

After you have that angle, there are 4 quadrants to a compass:

  • N 315-45 degrees
  • E 45-135 degrees
  • S 135-225 degrees
  • W 225-315 degrees

Set up a set of conditional statements for those ranges.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.