CMPS03 Compass Module


The CMPS03 compass module has been specifically designed for use in robots as an aid to navigation. The aim was to produce a unique number to represent the direction the robot is facing. The compass uses the Philips KMZ51 magnetic field sensor, which is sensitive enough to detect the Earths magnetic field. The output from two of them mounted at right angles to each other is used to compute the direction of the horizontal component of the Earths magnetic field.

Download and Installation

Download the ZIP archive and unzip into your Path to Arduino/libraries directory.

Start Arduino and select File->Sketchbook->Examples->Library CMPS03->CMPS03 from the Menu to load the example sketch.


The CMPS03 module should be connected to the I2C bus of the Arduino, i.e. the analog port pins 4 (SDA) and 5 (SCL). No pull-up resistors are needed, since the Atmel MCU already contains them internally.


CMPS03(uint8_t deviceId = 0x60)

Create a new instance of a CMPS03 sensor with the specified (7-bit) device id.

unsigned int read ()

Read the current sensor value. The returned value is in the range 0-3600.


The following example shows a simple CMPS03 read loop, that prints the sensor values every second onto the serial port.

#include "Wire.h"
#include "CMPS03.h"

CMPS03 cmps03;

void setup() {

void loop() {


The CMPS03 Arduino Library is licensed under the GNU Lesser General Public License Version 3.0 .

This page was last updated on 07. February 2016