Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Contents

LEGO MINDSTORMS NXT Color Sensor

Measure color or light intensity

Library

Simulink Support Package for LEGO MINDSTORMS NXT Hardware

Description

Measure color, or light intensity (luminance) from the LEGO 9841 Color Sensor. The sensor measures color using separate red, green, and blue (RGB) components.

If you run a simulation of a model that contains this block without the target hardware, this block outputs zeroes. See Block Produces Zeros or Does Nothing in Simulation.

Use the Color Sensor

Use the Color Sensor block to measure the color or light intensity of an object.

  1. Open the legonxtlib block library and copy the blocks shown to a new model.

  2. Connect the Color Sensor block to the LCD blocks.

  3. Double click each LCD block to open the block masks for each block.

    Use the Display at line parameters to select a different line number for each block.

    Use the Display label parameters to add an R, G, or B label for each line.

  4. Connect the color sensor to Port 1 on the NXT brick.

  5. Prepare and run the model on the NXT brick.

  6. Point the color sensor at a variety of well-lit colored objects and observe the measured red, green, and blue components of that color on the LCD. When you point the sensor at a bright white light, all three output values are near 255. When you point the sensor at a dark shadow, all three output values are low, nearer to 0.

  7. In the Color Sensor block, change the Sensor type parameter to Light. This action changes the block output for the red component, R, into an unlabeled block output for light measurements.

  8. Delete the broken connectors and unused LCD blocks from the model, and then run the model on the NXT brick.

  9. Point the color sensor at a variety of well-lit colored objects and observe the light measurements. When you point the sensor at a bright white light, the block output values are high, near 90. When you point the sensor at a dark shadow, all three output values are low, near 6.

    Note:   For accurate color measurements, position the sensor approximately 1 to 2 inches (2.5 to 5 cm) from the object.

Dialog Box

NXT brick input port

Select the NXT sensor port to which the sensor is connected. Avoid assigning multiple devices to the same port. The options are 1, 2, 3, or 4.

Sensor type

Select the type of measurement to perform, Color (the default) or Light.

When you select Color, the block outputs a 1-by-3 matrix of RGB values. Each value ranges from 0 (darkest) to 255 (brightest).

When you select Light, the block displays two new parameters, Emitted light and Output mode.

Emitted light

This parameter is only available when the Sensor type parameter is set to Light.

Use Emitted light to choose the color of light the LED on the sensor emits, or to turn the LED off. The options are Red, Green, Blue, White, and None.

Output mode

This parameter is only available when the Sensor type parameter is set to Light.

Select the range the block outputs, Normalized (0-100) or Raw A/D (0-1023).

When you select Normalized (0-100), the block outputs light intensity as normalized values that range from 0 (darkest) to 100 (brightest).

When you select Raw A/D (0-1023), the block outputs light intensity as raw values that ranges from 0 (darkest) to 1023 (brightest).

Sample time

Specify how often the block reads sensor values.

Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.

See Also

| |

External Web Sites

Was this topic helpful?