Learn about Sparki's Magnetometer


Lessons You Should Know

Sparki has a 3-Axis magnetometer. It is used to detect the magnetic field Sparki is experiencing. This can mean the earth’s magnetic field, the field generated by Sparki’s motors and wires, or many other sources. It can do this in all 3 XYZ axis, which are left/right (X), forward/backwards (Y), and up/down (Z). This is the same part that smartphones use to act as a compass.


How It Works

The magnetometer is what’s called a microelectromechanical, or MEMs device. MEMs are made of very tiny mechanical parts and wires too small to see, made in the same way microchips are made. Inside the part, too tiny to see, are tiny coils and a beam. Each axis has a beam. That beam has a pressure sensor on each side, and a coil wrapped around it passing current through it. Due to Lorentz force, the stronger the magnetic field, the more the bar with the current passing through it bends. The pressure sensors measure this bending, do calculations on how much magnetic field it means, and send this information to Sparki. Pretty complicated for such a tiny chip!

Magnetometer Diagram
The part has 3 different axis, left/right (X), forward/backwards (Y), and up/down (Z):

The direction of the arrows shows the positive direction of the reading. If the magnetic field is in the opposite direction, the reading will be negative.

Using the Part

With the basic Sparki code in place, you can measure the magnetic field in each axis using these commands: This command returns the magnetic field the magnetometer reads on the X, Y or Z axis in milliGauss. SparkiDuino already has code examples for you to use: File > Examples > Magnetometer