Fun with magnetometer / digital compass sensors



  • A few days ago I got a HMC5883L magnetometer from China. I do not post the link as it is the reseller is offline due to Chinese new year.

    Now I can think of two applications for it:

    1. Replacement for hall-sensors
      I have one of these cheap Chinese hall-sensors using a 3144 or 44e hall switch. They are not linear but switch when a magnetic flux of 30mT is detected.
      They did not work on my very old gas-meter, even if I could measure some magnetic field with an analog compass.
      I tried to measure the field with the magnetometer and I could see a very clear change in the field when gas is flowing.
      I did not write a proper code, but will keep you updated.
      On the pro side ist the high sensitivity of 70nT (about 500000 times better than the hall sensor) and also the low current consumption (100ยตA in measurement, 2ยตA in idle mode vs. 25mA on the hall sensor).
      On the con side is the rather high effort for signal processing in code (e.g. low pass filtering for getting rid of the earth magnetic field).

    2. Non-invasive current measurement
      The maximum sampling rate of the HMC5883L is 160Hz, which is in theory enough to signals of up to 80Hz.
      Hence it can be used to measure the magnetic field of 50Hz or 60Hz currents.
      I did a first test with my 60W solder iron. When holding the sensor to the cable I got a very clear Signal with an amplitude of about 20mT.
      It might be hard to calculate an exact current from this reading, as the magnetic field depends on the exact position of the sensor.
      But it can be used as a binary switch sensor which reports the power state of some device. One could e.g. use it to monitor the fridge and send an alarm if the fridge is running for too long.

    Has anyone any experiences with the applications above?


  • Mod

    @fleinze said:

    I'm struggling with readout of the magnet/piece of iron in my water sensor. I think I'm going to try your suggestion!

    On the con side is the rather high effort for signal processing in code

    This should be rather simple IMHO. Calculate the exponential moving average of the signal(s) and substract them from the actual value(s). A significant change will indicate a pulse.


  • Mod

    I can basically find two types of breakout board on Ali:

    I guess the first one included level converters fro 5V IO, and the other doesn't. How about your board, @fleinze ?
    Both seem to have an onboard 5V->3V3 regulator.



  • I am using the second one, which has a regulator but no level converter. It works with 5v but i will check if i can turn off the internal pull ups on the twi in arduino. (the board seems to have two 10k pull-ups for sda and sck)


  • Mod

    @fleinze I just received mine. These things are incredibly sensitive!
    When I approach the sensor with a neodimium magnet it 'sees' the magenet from over half a meter distance.
    You can easily use these as a distance sensor too.

    Next up is the water meter experiment ๐Ÿ˜‰


  • Mod

    Attached the HMC5883L to my water meter using some putty (just stuck it on the edge near the metal magnet on the big red arrow):

    0_1458070009000_2016-03-15 20.11.11.jpg

    I let the water run for a while and spilled around 20 litres (0.02m3). You can see the magnet has moved from the 5-digit to the 7-digit:

    0_1458070013698_2016-03-15 20.14.20.jpg

    Next is the chart of the HMC5883L's X/Y/Z readings (Range 8_1GA, average over 8 samples, 1 sample (horizontal pixel) per second):

    0_1458070295145_Naamloos.png

    You can clearly see the sensor readings starting to change when the valve opens and stop changing when it's close again!
    I didn't want to spill 100 litres just for a quick test, but I expect the curves to be sinusodial, and certainly periodic with the turning of the magnet.
    The position of the sensor isn't critical at all (in contrast to all other water meter sensors I've seen), you could even stick it on the closed lid of the water meter!
    Every position will generate a different swing of the X/Y/Z signals, so some clever software is required to translate this into (partial)rotations of the magnet.

    BTW I used this library and modified HMC5883L_simple.ino to output the data for the Arduino plotter.



  • Non-invasive current measurement with HMC5883L is as good as mosquito killing by the hammer - can be done but an overkill! ๐Ÿ™‚
    Non-invasive current measurements are greatly done with wire clamp/loops.
    HMC5883L is highly sensitive and low noise digital compass. It can be used in drones, smartphones, VR sets - any applications that needs to know change of physical object orientation in 3D space.
    We use it for vehicle detection sensor. Did a benchmark on RMS on temperature stability with half a dozen of other sensors, ST, NXP, Bosch. HMC is the best! ๐Ÿ™‚


Log in to reply
 

Suggested Topics

  • 87
  • 1
  • 10
  • 2
  • 9
  • 3

18
Online

11.2k
Users

11.1k
Topics

112.5k
Posts