Arduino Compass MPU9250 Magnetometer & OLED

Posted on

DIY Arduino Compass

Today, everyone has a compass on their smartphone devices. With various software, that has powerful features. Therefore, in this article, I will share how to make an Arduino compass using MPU9250 Magnetometer and I2C OLED SSD1306 with u8g2 Library.

MPU-9250 Magnetometer

MPU-9260 is an IC or chip in which there are 4 sensors, Accelerometer, Gyroscope, Magnetometer, and Temperature. For making this compass, we only use one sensor, the Magnetometer.

The magnetometer is a component that is able to read the direction of the North and South magnetic fields of the Earth by sensing the Earth’s magnetic lines of force. The magnetometer of the MPU9250 will provide 3 coordinates of the magnetic field namely X, Y, and Z.

Magnetometer Orientation:
The orientation of the axis direction to the IC position can be illustrated as shown in the following figure:
Arduino Compass MPU9250 Magnetometer & OLED

Magnetics Declination

After we get the values of the X, Y, and Z orientations, then we must know the Declination angle and why we need it.

By default, the magnetometer will only read Earth’s magnetic north and south, not Earth’s true north and south. So here it should be noted that:

  • Earth’s north ≠ Earth’s magnetic north
  • Earth’s south ≠ Earth’s magnetic south

The difference between Earth’s north and Earth’s magnetic north is depicted in angles, as well as south. Well, this angle is called the Magnetic Declination angle.

To find the magnetic declination value, you can read it in this article.

Wiring

Attention !!! The MPU9250 uses 3.3V. Make sure you connect to Arduino 3.3V.

In addition, connecting the MPU9250 Magnetometer and OLED SSD1306 I2C sensors to Arduino is very easy. Only by using 2 data cables are SDA and SDC connected together. Look at the picture below:

Tutorial MPU9250 Arduino Show Data to OLED U8g2 Library



On the next page, you will get the program code from this Compass.