Shop OBEX P1 Docs P2 Docs Learn Events
HMC5883L compass with external magnet — Parallax Forums

HMC5883L compass with external magnet

Adil AliAdil Ali Posts: 9
edited 2013-08-05 00:06 in Accessories
I am using the HMC5883L digital compass to get the north,east,south,west directions. (0 degrees - 360 degrees).
[compass connected to atmega, atmega connected to LCD]

When i get a magnet close to the magnetometer (compass), distortion happens on the heading (output), and when i move away the magnet from the magnetometer the header doesnt return back to its correct value. (no set/reset occurs)

Although the datasheet says set/reset is controlled automatically.

Any solutions?

Comments

  • garyggaryg Posts: 420
    edited 2012-12-01 17:31
    I did some experimenting with the HMC5883L compass
    This sensor is very sensitive to any magnetic field.
    I would really not put a known strong magnet close to the sensor.
    It's possible that placing a magnet in close proximity to this sensor will magnetize some metal near by.

    Any stray magnetic fields within a few feet of the sensor will cause it to read out in error.
    Even a 9 volt battery close to the sensor will cause reading errors.

    You might want to try turning off the power to the HMC5883L and leave it sit in the off state for a while.
    On power up, maybe it will have corrected itself.

    With my setup, I need to locate the HMC5883L in a particular area in my shop, then it consistently works ok.
    I need to still figure out how to correct for the errors generated by nearby magnetic fields.

    If I can figure out how to get the compass working accurately and consistently, I can use it in my robotic scarecrow platform.
    For now, it's on the shelf until I get an inspiration.
  • Adil AliAdil Ali Posts: 9
    edited 2012-12-04 09:53
    True, when i leave the compass powered off for a while, it gives the correct headings.
    I also need it on my robots , and i do not want any stray magnetic fields to deviate my results.

    Do you think magnetic field protection (shield) could help?

    Thank you for the helpful post.
    If you find any further solutions please let me know.
  • LeonLeon Posts: 7,620
    edited 2012-12-04 10:15
    You could try demagnetising anything you think might be magnetised by putting them close to an electromagnet energised by 50/60 Hz, and reducing the current to zero.
  • garyggaryg Posts: 420
    edited 2012-12-04 20:39
    While I've never tried Demagnetizing anything, Leon's suggestion may be worth a try.
    Seems like I remember hearing about doing something like that back in the 1980's when I was being trained as an ElectroMechanical Technician. The basics are true, unlike lots of info that's found on the internet.

    If you are thinking about Magnetic Shielding, there is something called MuMetal that is commonly used to shield magnetic fields.
    I started looking into this material based on someone's suggestion in a different thread on this site.
    MuMetal aparently is a Nickel-Iron alloy.
    The only source I know to get this from at this time is McMaster Carr. They are an industrial Jobber store.
    When I did some internet research on Magnetic shielding, I was a bit put off by the complexity of all of the descriptions.
    With my background, the descriptions and math are way above me.
    If the compass I have on the shelf starts calling me, I think my 1st instinct is to put about a 4"x4" piece of MuMetal under the compass.
    I have no clue if it will improve the stray magnetic field effect.

    That's just another of my two cents worth.

    gg
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-04 21:23
    The MuMetal needs to go around the source of the interference (motor etc.) not the compass. The interference source really needs to be completely enclosed with the MuMetal to work properly. The MuMetal will block the Earth's magnetic field from reaching the compass if you place it too close to the compass.
  • garyggaryg Posts: 420
    edited 2012-12-06 13:40
    Duane
    Do you know if the MuMetal placed close to the compass, but not enclosing the compass will affect the compass readings?
    My thought is to possibly enclose a platform in a MuMetal enclosure, then put the compass module, perhaps with a riser on top
    of the enclosure so the Compass is outside and on top.
    I know that in my situation, the compass is thrown off by things like flourescent lights and motors running in my shop.
    But I also know that my platform motors running also throw the compass readings off.
    Thanks
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-06 21:12
    I haven't used MuMetal myself, I'm just stating things I read on another forum (written by a guy who seems to know his stuff).

    He was pretty adamant that MuMetal was for shielding noise sources not for shielding a sensor. I think a compass has to be able to sense the magnetic field in all directions for it to be accurate. I believe the susceptibility to magnetic noise is one of the limitations of using a magnetic compass in direction finding. I don't think they generally work well indoors (but I'm far from an expert on the subject).
  • Adil AliAdil Ali Posts: 9
    edited 2012-12-07 03:49
    Seems like I am still having the same problem. Results do not return to its previous value when I move a strong magnet around the compass. I left the compass for a while and it still outputs the deviated result. (By the way, if the magnet is not too strong, readings return to its correct value instantly when i move it away)
    Maybe you will be wondering why am i testing it with a very strong magnet. This is because I am going to have an electromagnet on my robot and a compass, and i do not want the electromagnet to distort the compass output..

    Is there an external set/reset circuit for HMC5883L?

    HMC6352 datasheet says

    "The periodic Set/Reset function performs a re-alignment of the sensors magnetic domains in case of sensor perming (magnetic upset event)"

    "With the periodic Set/Reset bit set, the set/reset function occurs every few minutes."

    Do you think HMC6352 compass will solve my problem? Resets the distorted output every few minutes. Or it will be the same as HMC5883L?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-07 07:11
    Adil Ali wrote: »
    Maybe you will be wondering why am i testing it with a very strong magnet. This is because I am going to have an electromagnet on my robot and a compass, and i do not want the electromagnet to distort the compass output.

    Have you measured the magnitude of the magnetic field generated by the electromagnet? At a reasonable distance, it may not be nearly as strong as the field of a permanent magnet up close. Hopefully the electromagnet isn't so strong as to cause the sensor to loose its calibration.

    I haven't found the MuMetal forum link yet but there are several threads about compass calibration on the SparkFun forum. Here's one.

    I think you're likely to have the same sort of problem with other magnetic field sensors when used near a strong magnetic field. I think it's a common practice to keep a compass on a robot elevated by a dowel in order to keep it away from the robot's motors. Other electronic compass modules might not be as susceptible to this problem but I don't think any are immune to it.
  • Adil AliAdil Ali Posts: 9
    edited 2012-12-12 07:57
    Thank you for the link and for your effort.

    Solution:

    With digital compass + gyroscope, external magnetic field will not distort the results.
  • darwinsongdarwinsong Posts: 1
    edited 2013-08-05 00:06
    Adil Ali wrote: »
    Thank you for the link and for your effort.

    Solution:

    With digital compass + gyroscope, external magnetic field will not distort the results.
    I have exactly same problem with HMC5883L, what do you mean with the solution "With digital compass + gyroscope, external magnetic field will not distort the results" ? Did you change disgital compass IC from HMC5883L?
Sign In or Register to comment.