Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Color Sensor Service

Color Sensor Service

Microsoft Robotics

Glossary Item Box

Microsoft Robotics Developer StudioSend feedback on this topic

Color Sensor Service

In addition to the settings described in Device Services, the LEGO® MINDSTORMS NXT Color Sensor Service has the SensorMode setting. The color sensor has three LEDs which can be controlled by setting Mode in the configuration. The available modes are:

  • Color - All LEDs on and Reading is a Color Number value from 1-6 (See below)
  • Red - Red LED on and Reading is an intensity value (0-1023)
  • Green - Green LED on and Reading is an intensity value (0-1023)
  • Blue - Blue LED on and Reading is an intensity value (0-1023)
  • None - No LEDs on and Reading is an intensity value (0-1023)

These SensorMode values are defined in the ColorSensorMode enum so you can select them by name.

If not specified in a configuration file, the default SensorMode is Color, i.e. all LEDs will be turned on when the Color Sensor service is started.

Color mode is special in that the sensor tries to determine the color of the object in front of the sensor as one of the following six values which are based on the most common LEGO brick colors:

  • 1 - Black (or nothing in range)
  • 2 - Blue
  • 3 - Green
  • 4 - Yellow
  • 5 - Red
  • 6 - White

These Color Numbers are defined in the ColorNumber enum. The color names and color patches are displayed on the service web page so that you can easily see what the color sensor thinks the current color is.

Note that the color sensor tries to map to the nearest matching color. So for instance, if you point it at an orange object it might return either Red or Yellow depending on which color it is closest to. Also, the range of the color sensor is very limited -- only 1-2cm. This works well if the color sensor is mounted close to the objects being examined, such as in the Color Sorter model. It does not work well for the Shooterbot because the color sensor is positioned high on the robot pointing forward. On the Shooterbot, the color sensor is intended as a general-purpose light sensor (set the SensorMode to None).

The Red, Green and Blue modes each turn on one of the LEDs. You cannot turn on a combination of LEDs at the same time. If you are not interested in the reading from the sensor, you can make a simple light display with flashing colors.

When you set the SensorMode to None, all the LEDs are turned off. In this case the color sensor acts like the original light sensor, but it is more sensitive. This mode is good for line following if you place the sensor near the ground facing down. It can also be used to sense the ambient light level and can even "see" light bulbs several meters away.

The following diagram shows how to configure a Color Sensor in VPL.

Color Sensor Config


When you browse to the service web page the display differs slightly depending on which mode is selected. The diagrams below show respectively Color mode, Green mode, and None mode (no LEDs on). Note that in Green and None the Reading is an intensity value from 0-1023 so the color patch is displayed as a shade of grey although the drawing of the sensor shows the color of the LED. However, in Color mode the range is 1-6 corresponding to specific LEGO brick colors, so the web page displays both the name of the color and a corresponding color patch (which is Yellow in the screenshot below).

Color Mode Green Mode None Mode



© 2012 Microsoft Corporation. All Rights Reserved.

© 2015 Microsoft