Is there a sensor I could use which would let me know which direction an object is heading/facing? i.e. I have a servo that can rotate 0 to 180 degrees, and I have another sensor on a block. When I turn the block 45 degrees, I want the servo to also turn 45 degrees - I thought I could do this with a compass, but the varying magnetic fields make it impossible. Gyro/acc maybe? Except I don't know how to use that to solve this problem.

So in other words we need to know the block was rotated 45 degrees using a sensor on the block, which tells the servo to rotate 45 degrees.

  • 2
    You can lookup "sensor fusion" (which is a complicated matter) and "MPU6050", which is a cheap board with some hardware support and plenty of examples for it - perhaps it might be what you need.
    – Mishony
    Jun 21, 2016 at 7:10
  • Great thanks, I think that might work I have used that sensor before for an indoor positioning system / IMU setup -- one question though is there a way to have two separate MPU6050 synchronize orientations? That was the reason for my compass system - both knew which way was north irregardless of when they were turned on so I could use that as a calibration point.
    – eWizardII
    Jun 21, 2016 at 7:37
  • Lookup Magnetometer sensor.
    – Gerben
    Jun 21, 2016 at 13:32
  • You could use the accelerometer to "synchronize orientation" because gravity always points down, but that will only work if the two sensors rotate on an axis that does not line up with gravity (e.g. they don't rotate around an axis pointed up). Similarly, a magnetometer won't work if the table rotates around the north vector.
    – BrettAM
    Jul 27, 2016 at 18:40

1 Answer 1


Use a gyro, it will give you the angle. Gyros are difficult to find spare, so you should buy an IMU like MPU6050 that contains also an accelerometer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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