Magnetic Ruler

by lingib in Circuits > Arduino

163 Views, 1 Favorites, 0 Comments

Magnetic Ruler

magnetic_ruler1.jpg
magnetic_ruler2.jpg
West_to_East.png
East_to_West.png
Magnetic Ruler

This instructable explains how to make a “magnetic ruler” for measuring precise distances.


The “magnetic Ruler” comprises a number of neodymium button magnets evenly spaced NSNSNS, an MLX90393 triaxial magnetometer module, and an Arduino UNO R3 microcontroller.


Construction is simple ... the accuracy is excellent.


Images

Fig.1 (cover) Top view

Fig.2 Underside showing the magnets fixed NSNSNS

Fig.3 Serial Monitor display when travelling West-to-East [1]

Fig.4 Serial Monitor display when travelling East-to-West

The video shows the ruler in action


Note

[1]

The wobbles in the ramps shown in fig3. & fig.4 are due to handshake


Supplies

The following parts were obtained from https://www.aliexpress.com/


  1. 1 only packet 5x5x1 mm neodymium magnets
  2. 1 only MLX90939 3D sensor module
  3. 1 only I2C level converter
  4. 1 only Arduino prototype board
  5. 1 only Arduino UNO R3 microcontroller with USB cable


The following parts were obtained locally:

  1. I only roll of double-side tape
  2. 1 only roll of single sided tape
  3. 1 only 0.5 inch spacer such as a rubber
  4. Cardboard
  5. Hookup wire


Excluding postage, the estimated cost for the above items is less than $50.

Circuit Diagram

Magnetic Ruler.png

The circuit diagram is shown in fig.1 above

The I2C level converter is required as the MLX90393 requires 3 volts

Theory

The MLX90393 is a three-axis magnetometer based on Melexis’ patented Triaxis® magnetoresistive technology. It provides raw X, Y and Z magnetic field measurements, which are used here to construct a magnetic ruler.


Looking at Bx and Bz individually

For a one-dimensional (1D) NSNS… magnetic array and a fixed sensor height:

  1. Bz varies approximately as a sine
  2. Bx varies approximately as a cosine


Between adjacent poles (N → S or S → N):

  1. Each component completes half of a sinewave
  2. A full sine/cosine cycle corresponds to two poles (N → S → N)


The vector view

Now look at the magnetic field vector:

  1. V = (Bx, Bz)


As the sensor moves along the X direction:

  1. The tip of the vector rotates smoothly
  2. It traces (approximately) a circle in the Bx–Bz plane
  3. The rotation direction (clockwise or counter-clockwise) depends on:
  4. the magnet polarity order (NS vs SN)
  5. which axes are supplied to atan2()


Vector angle behaviour between poles

Using the trigonometry relationships:

  1. sine/cosine = tangent
  2. angle = atan2(Bz, Bx)


Then:

  1. The vector rotates by 180° between two adjacent poles (N → S)
  2. These rotations accumulate: 180°, 360°, 540°, 720° …
  3. The vector rotates by 360° between N → S → N
  4. The sign (direction) depends on convention
  5. The magnitude of rotation is invariant


Why the magnetic ruler works

The magnet array converts linear motion → angular phase


That phase is:

  1. smooth
  2. monotonic
  3. largely immune to absolute field strength


Position becomes:

  1. position = AccumulatedVectorAngle / 180°


Construction

Construction:

  1. Lay a length of double-side tape on a sheet of non-magnetic material.
  2. Evenly space the magnets NSNS on the double-sided tape. Being double-sided prevents the magnets shifting or flipping.
  3. Cover the magnets with normal single-sided tape. This prevents the magnets falling off.
  4. Done


Software

Installation:

  1. Download the attached file “MLX90393_magnetic_ruler.ino”
  2. Copy the contents into a fresh Arduino sketch and save it as “magnetic_ruler” (without the quotes). Use a text editor suchas “Notepad++” ... not a word processor.
  3. Upload the sketch to your Arduino.
  4. Done


Calibration & Use

  1. The software auto-calibrates.
  2. Place the MLX90393 sensor on a non-magnetic support. The support needs to be high enough to prevent the magnetic fields overloading the sensor. I found a 0.5 inch high eraser worked fine.
  3. To use simply place the MLX90393 sensor over the first magnet and power up.
  4. Sliding the sensor towards the far end will cause the readings to ramp upwards.
  5. Changing direction causes the readings to decrease.


Summary

This instructable explains how to make a “magnetic ruler” for measuring precise distances.


The “magnetic Ruler” comprises a number of neodymium button magnets evenly spaced NSNSNS, an MLX90393 triaxial magnetometer module, and an Arduino UNO R3 microcontroller.


Construction is simple ... the accuracy is excellent.


Excluding postage, the estimated cost to make this ruler is less than $50.

  Click here   to view my other instructables.