Icon of block

Color Sensor V2 Block

This block supports the HiTechnic Color Sensor Version 2 (V2) that measures the color of an object or surface placed in front of the sensor. It returns the reading as both a color number ranging from 0 (black) to 17 (white) and as a set of red, green and blue values. Using data wires, it can send out the color number, red, green and blue values and a logic signal (true/false) based on whether the color falls inside or outside a trigger range.

A trigger range consists of upper and lower limit values in a range of numbers where a change in the reading results in the condition of being either inside or outside the range. For example, you might program your robot to detect orange or red so you could set the trigger range to be from 8 (orange) to 9 (red). When an orange or red object is placed in front of the sensor, the condition will be true.

Specify the trigger points by using the slider or by typing the values into the input boxes. To specify the portion of the color sensor's range (inside or outside the trigger range) that will generate the "true" signal, use the radio buttons or the pull-down menu. The "true" portion of the range will be in color; the "false" portion will be gray.

The default setting for the color sensor block is for the whole color range to trigger a "true" signal. The compare function above the range allows you to switch the "true" portion of the range to be either inside or outside the range selected.

You must drag at least one output data wire from this block's data hub to another block for any information to be sent.

Display Settings

Image of block

  1. The number shows which of your NXT's ports are connected to the color sensor. You can change this number in the configuration panel if you need to. If the sensor is connected to the Sensor Multiplexer this shows the NXT port connected to the Multiplexer.
  2. The right most icon indicates the sensor mode, lit if in active mode and unlit in passive or raw mode. The left most icon indicates the Multiplexer port connected to the sensor if the Multiplexer is selected.
  3. 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. The trigger range and other features can be set dynamically by connecting an input data wire. (See the Data Hub section below for more information.)

Configuring the Color Sensor Block

Image of configuration panel Image of configuration panel

  1. Choose the NXT port your color sensor is connected to. By default, the block will be set to port 2 for a color sensor. You can change this selection if you need to.
    To connect the color sensor via the HiTechnic Sensor Multiplexer click on the arrow on the right side of the Port panel. Select the MUX checkbox and select the Multiplexer (MUX) port connected to the color sensor. Click the right side arrow again and select the NXT port the Sensor Multiplexer is connected to. Note that the Mode cannot be selected when using the Multiplexer.
  2. If you choose the Compare function Inside Range above the slider, the block will be triggered when the detected color range is between the two trigger values; select Outside Range to trigger the block when the detected color range is outside the two trigger values. Use the slider to set the trigger values or type them directly into the input boxes (0 - 17).
  3. Select the Color Sensor Mode. The three modes available are;

    Active - Returns a calculated 'color number' and uses the sensor's internal light source to illuminate the target surface.
    Passive - The sensor detects external light sources with the sensor's internal light source switched off. In this mode the color number output is not computed as normal and instead shows the color of the light detected as shown below.
    Raw - Returns raw values from the sensor element with the internal light source illuminating the target surface.

Note: 1. When measuring the color of a target surface, light from the sensor's internal light source can reflect from the target and interfere with readings. To minimize problems caused by reflections, place the color sensor at a slight angle so it is not positioned exactly perpendicular to the target surface.
2. When accessing the color sensor via the HiTechnic Sensor Multiplexer only Active mode is available.

Configuring the Color Sensor block's Data Hub

You can control the Color Sensor block dynamically by connecting data wires (from other block's data hubs) to the Color Sensor block's data hub.

Open a block's data hub by clicking the tab at the lower left edge of the block after it has been placed on the work area.

Image showing unopened tab on a generic block

Data wires carrying input information to a block are connected to the plugs on the left side of its data hub. Data wires carrying output information are connected to the plugs on the right side.

Image of data wires

[A] Input plug
[B] Output plug
[C] Number data wire (yellow)
[D] Logic data wire (green)
[E] Text data wire (orange)
[F] Broken data wire (gray)

Passing data from the input plug to the output plug

If an input plug has a corresponding output plug (see A above), the input data will pass through from the input plug to the output plug without being changed. In this case, you can only use the output plug if the input plug is connected to an input data wire; connecting an output data wire to such an output plug without a connected input data wire will cause the output data wire to be "broken" (and colored gray).

Data wires carry specific types of data

Each data wire carries a specific type of data between blocks. For example, if a data wire is dragged from a logic plug on a block's data hub, it can only be connected to a logic plug on another block's data hub. The chart below shows what kind of data each plug can accept or send out.

Data wire colors

Data wires are identified with specific colors: wires carrying number data are colored yellow, wires carrying logic data are colored green, and wires carrying text data are colored orange.

"Broken" data wires

If you try to connect a data wire to a plug of the wrong data type, the data wire will be broken (and colored gray). You will not be able to download your program if a data wire is broken.

If you click a broken wire you can read why it is broken in the small help window in the lower right corner of the work area.

Data must be within the possible range of the plug

If an input data wire transmits a value outside the possible range of the plug it is connected to, the block will either ignore the value or change it to a value within its range. For plugs that allow just a few input values (example: just 0, 1, or 2), the plug will ignore the input if a value arrives outside its range.

For plugs that accept larger input ranges (example: 0 - 100), the plug will force any input outside its range to fit. For example, if a Move block's Power plug receives an input value of 150, the block will change the input value to 100 (i.e., a number within the Power plug's range).

Color Sensor block Data Hub plugs

You must click on the Data Hub to open it as shown.

Image of block
  1. NXT port number connected to the color sensor or if using a Sensor Multiplexer, the NXT port connected to the Sensor Multiplexer.
  2. Color Number
  3. Red value output
  4. Green value output
  5. Blue value output
  6. White value output. (Only available in Passive or Raw modes)
  7. Logical output identifying if the color number is inside/outside the selected range
  8. Range (0 - Inside, 1 - Outside)
  9. Lower limit of range
  10. Upper limit of range
  11. Mode (0=Active, 1=Passive, 2=Raw)
  12. MUX, Boolean to select sensor is connected to a Sensor Multiplexer (True=Multiplexer, False=no Multiplexer)
  13. Multiplexer Port number connected to the color sensor
  14. Datalog data if using datalogging

 

Decoding the color number

Image of configuration panel

The Color sensor converts the red, green and blue values into a color number. While advanced users may wish to process the red, green and blue values themselves, many users prefer to rely on the built-in color estimator.

In Active mode the color number ranges from 0 - 17 where 0 represents black or nothing in front of the sensor while 17 will be returned for white.
In between these two values, 1 - 10 are used to encode highly saturated colors while 11 - 16 encode very light colors.

In Passive and Raw modes the color number will range from 1 - 3 indicating the dominant color present as 1 = Red, 2 = Green, 3 = Blue.

The accompanying chart shows the relationship between the spectrum of detectable colors and the resulting color number.

 

Using Range

The Compare lets you set a range and easily determine if you are 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.

If you wish to test for a specific color, say red (9), you can set both the range sliders to 9. By selecting inside range, only red will trigger a true output whereas selecting outside range, anything but red will trigger a true output. Note that this will include black or nothing in front of the sensor.

For more information visit www.hitechnic.com or contact HiTechnic support at support@hitechnic.com.