HiTechnic NXT Color Sensor for LEGO Mindstorms NXT
Introduction
The NXT Color Sensor operates by using three different color light emitting diodes (LED) to illuminate the target surface and measures the intensity of each color reflected by the surface. Using the relative intensity of each color reflection, the color sensor calculates a Color Number that is returned to the NXT program.
The Color Sensor connects to an NXT sensor port using a standard NXT wire and uses the digital I2C communications protocol. The Color Number calculated by the sensor is refreshed approximately 100 times per second.
The Color Sensor is housed in a standard Mindstorms sensor housing to match the other Mindstorms elements.
To test your new sensor, plug it into port 2 of your NXT and select View > Ultrasonic cm > Port 2. Position the sensor approximately 1/4" (6mm) from a colored surface. A Color Number in the range of 0 - 17 will be displayed. As you move the sensor over different colored surfaces, the readings will change. (0 will display as ?????? while in View mode.)
Programming
Mindstorms NXT-G
The Color Sensor can be programmed using LEGO Mindstorms NXT Software Color Sensor Block. If the Color Sensor Block is not available you may use the standard Ultrasonic Block.
Ultrasonic Block
If using the Ultrasonic Block to program the Color Sensor, configure the block to centimeter mode as shown.

The Ultrasonic Block will return the Color Number which will be in the range 0 - 17.
Color Sensor Block
The Color Sensor Block is designed to support the HiTechnic Color Sensor.
1. This plug wires the number for which of your NXT’s ports are connected to the Color Sensor.
2. This plug wires the lower limit number for the Inside/Outside compare function.
3. This plug wires the upper limit number for the Inside/Outside compare function.
4. This plug wires the Color Number.
5. This plug outputs the relative Red value.
6. This plug outputs the relative Green value.
7. This plug outputs the relative Blue value.
8. This plug outputs the Inside/Outside logical value.
Color Front Panel
Port allows you to select the NXT port the compass is plugged into.
Compare
Compares the Color Number to the range set and sets the logic value to show if the value is inside or outside the range.
Using Range
The Compare lets you set a range and easily determine if the Color Number is inside or outside the range.
The Components for using the Range function are;
Inside Range / Outside Range: Select if you want to test for a Color Number inside the range or outside the range.
A: The lower limit of the range (0 – 17)
B: The upper limit of the range (0 – 17)
To use the Range function, set the lower and upper limit of your range and whether you want to test for inside or outside the range.
Examples showing the logical result.
A |
B |
Range |
Color Number |
Logical Value |
8 |
12 |
Inside Range |
10 |
|
8 |
12 |
Inside Range |
15 |
|
8 |
12 |
Outside Range |
10 |
|
8 |
12 |
Outside Range |
15 |
|
Color Number Chart
The Color Number chart shows the relationship between the target color and the Color Number returned by the Color Sensor.
Sensor Register Layout
The color firmware supports the standard Lego company’s sensor memory model.
Address |
Type |
Contents |
00 – 07H |
chars |
Sensor version number |
08 – 0FH |
chars |
Manufacturer |
10 – 17H |
chars |
Sensor type |
18 – 3DH |
bytes |
Not used |
3E, 3FH |
chars |
Reserved |
40H |
byte |
Not used |
41H |
byte |
Command |
42H |
byte |
Color number |
43H |
byte |
Red reading |
44H |
byte |
Green reading |
45H |
byte |
Blue reading |
The Sensor version number field will report a revision number in the format “Vn.m” where n is the major version number and m is the revision level. Revision numbers will typically reflect the firmware level. The version number will be used to indicate the hardware level.
The Manufacturer field will contain “HiTechnc”.
The Sensor type field will contain “Color”.
The Command field reserved for future use.
The Color number field will return a single number color estimate.
The Red, Green and Blue reading fields will return the current detection levels for the three color components.
Other Programming Environments
RobotC
All features of the HiTechnic Color Sensor can be accessed using RobotC. For more information go to http://www-education.rec.ri.cmu.edu/robotc/.
NXC
NXC is a C programming language compiler that can access all Color Sensor features. For more information go to http://bricxcc.sourceforge.net/nbc/.
Notes:
-
The HiTechnic Color Sensor operates best when positioned straight above the target surface and not at an angle to the target surface.
-
NXT Firmware version 1.03 or later must be loaded in the NXT for the compass to operate correctly. You can check the firmware version by displaying the NXT Window in the Mindstorms software.

