3.12 (Direction Recognition) Geomagnetic Sensor

3.12.1 Overview

AK8975C geomagnetic sensor is a three-axis electronic compass IC with high sensitivity. It can output 13-bit data and accurately detect X, Y, Z axes geomagnetic values. Thus, it is suitable for portable devices with navigation function such as mobile phones and tablets.

3.12.2 Schematic Diagram

6-12

The AK8975C geomagnetic sensor works in the principle of electromagnetic induction. It takes the Earth’s magnetic field as a measurement benchmark to sense changes in the magnetic field through its internal magnetic material and coils. Specifically, when the magnetic material is affected by geomagnetic field, a directional constrained electron spin deflection will happen due to the field force, which in turn forms a magnetic field. This field induces potential signals in the coil.

This sensor amplifies and processes the induced potential signals, which are then transmitted to the system for further calculation, analysis and processing. So it measures geomagnetic magnetic field in the axis X, Y, and Z to determine the direction.

3.12.3 Code Blocks

  1. 6-12

    This block is used to initialize AK8975 geomagnetic sensor.

  2. j40

    This block reads the magnetic field direction.

  3. j41

    This block reads the values on axis X, Y and Z:

    6-12

3.12.4 Test Code

3.12.4.1 Build Code

There are two ways to upload the code: directly open the code file we provide; or manually build blocks.

Directly open the code file we provide:

  1. Click and choose Load from your computer

  1. We have already downloaded the codes on computer desktop, so open the file and choose 3-12-ak8975.sb3

Manually build blocks:

  1. In events, find j1 block.

  2. In 6-12, put j35 under j1

  3. In serial, drag j12 and set baud rate to 9600, and put it under j35

  4. In control, drag j2.6-4-4-1-1

6-2

  1. In serial, put j13 in and set to print “X:” in no-warp mode.

  2. Add a image-20240701141959486 and set to no-warp mode.

  3. In , put into the printing content of j13, and set to read axis “X”.

    6-12

  4. Duplicate 6-12 and change to read “ Y:”(the two spaces separates the two values to be output). Set to read value in axis “Y”.

  5. Duplicate 6-12and change to read “ Z:”(the spaces separates the two values to be output). Set to read value in axis “Z”.

  6. Duplicate 6-12and change to read “ Direction:”(the spaces separates the two values to be output).

  7. In , put into the printing content of j13 and set mode to warp.

  8. Add a delay of 1S for better observing the results.

Complete Test Code

6-12-4-1-5

3.12.4.2 Test Result

After uploading code, the serial monitor prints the sensor values. Move the coding box to see the changes of these values.

6-12