dCompass for LEGO MINDSTORMS NXT Introduction

The Dexter Industries dCompass is a compass sensor for LEGO® MINDSTORMS® NXT.  This compact sensor detects magnetic fields for navigation.  Using a magnetic sensor, the sensor is able to measure the earth’s magnetic field and returns a magnetic heading, telling you which way your robot is heading.  The device can be used without calibration and can be calibrated with software to account for magnetic fields to deliver a highly accurate compass heading.


To setup the dCompass, simply plug it into any one of the four sensor ports on the NXT.  The dCompass will work on any of the four sensor ports.

  • Prevent stress damage to the board: be sure to use both of NXT holes to mount to LEGO contraptions.
  • Calibration: The dCompass needs to be calibrated on a flat surface.
  • Mounting Holes: LEGO crosses can be used to mount the dCompassto your robot.


The dCompass is supported in NXT-G, Labview, RobotC, NXC and Lejos.  Examples, blocks, and drivers can be downloaded from our download section.

The dCompass can be used as-is, but for increased accuracy, we recommend calibrating the sensor.  You may find it necessary to calibrate the dCompass for each robot you build.

NXT-G Software:

Two blocks for NXT-G can be downloaded from our download section.  The first block is for reading the dCompass, the second block is for calibrating the dCompass.

dCompass Read Block

dCompass Block: The block to read the dCompass has three connections:  one to specify the sensor port, one that provides the heading reading in degrees, and one that allows the input of the Offset.  To avoid problems with freezing up, you have to run the Calibration block at least once.

Offset: Offset is the angle between the heading on the compass reading north and the direction of true north.  Offset can be caused by magnetic deviation, motors, and other electronic parts.  Offset can usually be corrected with our software to provide true North.  Enter the degrees of offset from true north the compass reads when pointing towards true north and the block will automatically correct for the deviation.

The control panel for the NXT-G Block for the dCompass.

Calibration Block: The calibration block can be run to calibrate the dCompass.  This block can be run once for a particular robot, and can help offset any magnetic fields from the NXT, motors, or other magnetic components.  The block stores a data file on the NXT which is accessed by the dCompass Block to provide a calibrated reading of the dCompass.

Running the calibration block is very simple.  The block will display instructions on the screen, telling you how to calibrate the dCompass.  The instructions will tell you to rotate the compass a full 360 degrees in each direction (this may mean rotating you robot 360 degrees).  The compass will count from 0 to 1000.  The calibration program is finished when the screen clears.

  • The block can be run alone or before a program using the dCompass.
  • Calibration should be done with the dCompass flat to the ground.

Technical Details

When coupled with an IMU, the sensor can measure magnetic direction in any dimension; the sensor is a 3-D compass.  The Honeywell HMC5883L sensor is used, providing a range of measurement from milli-gauss to 8 gauss.  The sensor updates readings every 13 ms, or at a rate of 75 hz.

The sensor communicates with the NXT via I2C and can be placed on any port.  The I2C address of the dCompass is 0x3C.  More information on the registers can be found in the HMC5883L datasheet.

The dCompass consumes less than 1 mA of power.

Other Links and Examples:


Mounting the dCompass for Magnetic Interference

Don’t do this with your dCompass. Courtesy of BotBench.com

A: Placing the dCompass close to the NXT module, such as in the picture to the right, can result in magnetic interference that distorts the compass readings.  This can also happen if the sensor is too close to a motor or another magnetic device.

Got a question?  Ask on our forum!