Measure And Display The Earth's Magnetic Field

About the project

This project shows how to use Pmod CMPS2 and Arduino Uno to measure and display the Earth's magnetic field components. The 3 components of the magnetic field, module, & angle are displayed in the serial monitor.

Project info

Difficulty: Easy

Platforms: ArduinoDigilent

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Pmod CMPS2 Pmod CMPS2 x 1
Arduino Uno - R3 Arduino Uno - R3 x 1

Software apps and online services

Arduino Arduino


This is a demo project for the Digilent Pmod CMPS2. The X, Y and Z components of Earth's magnetic field are measured, converted in mG (milliGauss) and displayed on the Serial monitor. The module of the components and the angle of the device is also calculated and displayed (calculations are made according to the Pmod's datasheet). To control the Pmod, an Arduino UNO is used, which also sends the data to the computer. To communicate with the peripheral device, I2C communication protocol is used, the device address is 0x30. Data is received as two 8-bit parts of a 16-bit number in two's complement form.

Schematics, diagrams and documents

Pmod CMPS2 and Arduino Uno Fritzing Image


Pmod CMPS2 and Arduino Uno Code


Photo of Digilent Inc

Digilent Inc

Digilent Inc., a National Instruments company, is a leader in the design, manufacture and worldwide distribution of FPGA development boards and Test and Measurement devices for both industry and education. Since our founding in 2000, Digilent has partnered with different leading semiconductor companies including Xilinx, Microchip, Analog Devices, ISSI and Texas Instruments to bring products with the latest embedded & electronics technology. Our expert team of engineers, combined with our manufacturing services and worldwide distribution has made us an ideal partner for several leading technology providers. We want to enable our partners to be successful through well designed, high quality and well manufactured hardware.


Leave your feedback...