The NXT Magnetic Sensor will enable you to build robots that can detect magnetic fields. The sensor detects magnetic fields that are present around the front of the sensor in a vertical orientation.
The sensor detects magnetic fields when the orientation of the magnet is as shown below.
When the orientation of the magnetic field has north uppermost, the reading will increase. If the magnet is presented sideways, it may not be detected.
The Magnetic Sensor connects to an NXT sensor port using a standard NXT wire and uses the analog sensor interface. The sensor can be read up to approximately 300 times per second.
The Magnetic Sensor is housed in a standard Mindstorms sensor housing to match the other Mindstorms elements.
To quick test your new sensor, plug it into port 1 of your NXT brick and select View – Ambient light – Port 1. As you bring a magnet close to the front of the sensor, you'll notice that the readings will change as the magnet gets closer.
The Magnetic Sensor can be programmed using LEGO Mindstorms NXT-G Software by importing the Magnetic Sensor Block. This and other HiTechnic sensor programming blocks are available from the downloads page.
The Magnetic Sensor Block provides access to the sensor output in addition to other features.
- The number shows which of your NXT's ports are connected to the Magnetic Sensor. You can change this number in the configuration panel if you need to.
- The block's data hub will open automatically when the block is placed in the work area. At least one data wire must be dragged from the block's output plug to another block's data hub. (See the Data Hub section below for more information.)
Configuring the Magnetic Sensor Block
The sensor may be connected directly to an NXT sensor port or via the HiTechnic Sensor Multiplexer (MUX). When configuring the sensor via the multiplexer, there are two port selections to make. The first is the NXT to MUX connection and the second, the MUX to SENSOR connection.
The Magnetic Reading output indicates the relative strength of the magnetic field measured. When the sensor is not in the proximity of a magnetic field, the output should be zero. Due to manufacturing tolerances, temperature and other effects, the output may be a small positive or negative number. To cancel out this zero offset error, also referred to as bias, an offset input can be applied.