I am trying to build a simple RC rover (car with only two wheels). On certain commands, I want it to rotate a specific number of degrees into a direction or another (don't want military precision). In other words, to change it's orientation by controlling the two wheels.

I wanted to use a cheap compass like this: https://www.pololu.com/product/2127 (LSM303D) But I heard that it won't work inside buildings; my rover will be used inside.

But in my case, I don't want to know the current orientation of my car, I just want to rotate an exact number of degrees into a direction relative to current orientation (even if current orientation is wrong).

Will it work in my case?

Do I have any other options to play around?

PS: Another possibility would be to use stepper motors. But this method is not pretty accurate as the contact surface of wheels may be smooth.

What about a gyroscope?

  • \$\begingroup\$ You need a gyro. Compass will help too. then you fuse them using Kalman filter. \$\endgroup\$
    – Eugene Sh.
    Commented Apr 4, 2017 at 16:14
  • \$\begingroup\$ Then you need better tires. \$\endgroup\$ Commented Apr 4, 2017 at 16:16
  • \$\begingroup\$ Use I&Q magnetic coils, to measure magnitude and phase of a wall-mounted coil that provides a tone-burst once a second in a convenient ISM band. The I&Q gives a vector; the SNR will set the accuracy. \$\endgroup\$ Commented Apr 4, 2017 at 16:22
  • 1
    \$\begingroup\$ That magnetic compass should work indoors, but will be affected to some extent by nearby steel, such as rebar in a concrete floor. \$\endgroup\$ Commented Apr 4, 2017 at 16:51
  • \$\begingroup\$ I was wondering if it would be possible to use only a gyroscope... \$\endgroup\$
    – caffeine
    Commented Apr 5, 2017 at 11:07

2 Answers 2


The reason the manufacturer says the compass "doesn't work" indoors is because there can be various magnetic sources indoors. The compass still works fine telling you which direction the magnetic field north lines go, but that direction may have little to do with the earth's magnetic field.

Since these magnetic source are quite localized, the apparent direction can change significantly as the car drives around on the floor of a single room. This makes such a compass useless for navigation.

However, turning in place might still work. The car wouldn't be changing location, so whatever magnetic field is around it should be fairly consistent as the car turns in place. You might get away with stopping the car, looking at the magnetic field direction, turning in place some fixed amount relative to the magnetic field, then moving again after the turn. Doing a broad turn while also moving is less likely to work as expected.


Have seen this kind of direction sensing work, but it isn't easy. Depending on your location, one component of the compass chip is vertical. Near the north or south pole, the vertical component dominates, and the X,Y components are very small. Any tilt must be corrected in a 3-dimensional manner - that is why the accelerometer is included. You are interested in the x-y plane to extract direction information, but part of the z component will likely reflect to x-y plane. In Northern USA, the Z-axis dip angle (from vertical) is about 70 degrees.
Peter Bennett has mentioned one problem indoors (add conduit to rebar and steel structures as magnetic disturbers). Another problem involves DC current in your robot wiring affecting compass direction - current-carrying wires produce magnetic fields too. You may have to mount this module well away from other electronics and motors.


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.