Color Sensor#

Introduction#

The Color Sensor category includes blocks that report color-based information from a VEX IQ Color Sensor. These blocks allow your robot to detect when an object is present, recognize specific colors, and return visual data such as brightness and hue.

You can also use blocks to configure the brightness of the sensor’s internal light. These tools are ideal for programs that need to react to colored objects, lighting conditions, or sensor feedback in real time.

Below is a list of all blocks:

set Color light#

The set Color light stack block sets how bright the Color Sensor’s light is. The light can help the Color Sensor detect objects and colors more clearly.

A higher percentage makes the light brighter. A lower percentage makes the light dimmer.

If the Color Sensor’s light is off, setting the light power above 0% will turn the light on.

If the Color Sensor’s light is on, setting the light power at 0% will turn the light off.

    set [Color1 v] light to (50) %

Parameters

Description

color sensor

Which Color Sensor’s light brightness to set, configured in the Devices window.

brightness

The brightness of the Color Sensor’s light from 0% to 100% as an integer.

Example

    when started
    [Light up the Color Sensor dimmer.]
    set [Color1 v] light to (25) %
    wait (2) seconds
    [Light up the Color Sensor brighter.]
    set [Color1 v] light to (100) %

Color found an object?#

The Color found an object? Boolean block reports whether the Color Sensor has detected any object.

  • True — The Color Sensor has detected an object.

  • False — The Color Sensor has not detected an object.

    <[Color1 v] found an object?>

Parameters

Description

color sensor

Which Color Sensor to use, configured in the Devices window.

Example

    when started
    [Print a different message when an object is in front of the Color Sensor.]
    forever
    set cursor to row (1) column (1) on [Brain v]
    if <[Color1 v] found an object?> then
    print [Object detected] on [Brain v] ▶
    else
    print [Nothing detected] on [Brain v] ▶
    end
    clear row (1) on [Brain v]

Color detects color?#

The Color detects color? Boolean block reports whether the Color Sensor has detected a specific color.

  • True — The Color Sensor has detected the specified color.

  • False — The Color Sensor has not detected the specified color.

    <[Color1 v] detects [red v]?>

Parameters

Description

color sensor

Which Color Sensor to use, configured in the Devices window.

color

Which color to check for:

  • red - Hue value between 340° and 20°
  • green - Hue value between 80° and 140°
  • blue - Hue value between 201° and 240°
  • white
  • yellow - Hue value between 40° and 59°
  • orange - Hue value between 25° and 30°
  • purple - Hue value between 280° and 320°
  • red violet - Hue value between 320° and 340°
  • violet
  • blue violet - Hue value between 240° and 280°
  • blue green - Hue value between 141° and 200°
  • yellow green - Hue value between 60° and 80°
  • yellow orange - Hue value between 30° and 39°
  • red orange - Hue value between 20° and 25°

Example

    when started
    [Turn until the Color Sensor detects green.]
    turn [right v]
    wait until <[Color1 v] detects [green v]?>
    stop driving

Color color name#

The Color color name reporter block reports the name of the color detected by the Color Sensor as a String.

Possible colors are:

  • red

  • green

  • blue

  • white

  • yellow

  • orange

  • purple

  • red violet

  • violet

  • blue violet

  • blue green

  • yellow green

  • yellow orange

  • red orange

Note: This block can be inserted into the set Touch LED color block to make the Touch LED match the detected color.

    ([Color1 v] color name)

Parameters

Description

color sensor

Which Color Sensor to use, configured in the Devices window.

Example

    when started
    [Stop and print when the Color Sensor detects green.]
    turn [right v]
    wait until <[Color1 v] detects [green v]?>
    stop driving
    print ([Color1 v] color name) on [Brain v] ◀ and set cursor to next row

Color brightness#

The Color brightness reporter block reports how bright the detected color is, as a percentage from 0% to 100%.

A higher percentage means the Color Sensor detects more light. A lower percentage means the Color Sensor detects less light.

    ([Color1 v] brightness in %)

Parameters

Description

color sensor

Which Color Sensor to use, configured in the Devices window.

Example

    when started
    [Stop and print the brightness when the Color Sensor detects green.]
    turn [right v]
    wait until <[Color1 v] detects [green v]?>
    stop driving
    print ([Color1 v] brightness in %) on [Brain v] ◀ and set cursor to next row

Color hue#

The Color hue reporter block reports the hue detected by the Color Sensor as a number from 0 to 359 degrees.

Hue is a way to describe color using numbers around a color wheel, as shown below:

A circular color wheel displaying a full spectrum of hues labeled with degree values around the perimeter, increasing in 30-degree increments from 0° at the top to 360°.

    ([Color1 v] hue in degrees)

Parameters

Description

color sensor

Which Color Sensor to use, configured in the Devices window.

Example

    when started
    [Print when the Color Sensor detects pink.]
    forever
    clear all rows on [Brain v]
    set cursor to row (1) column (1) on [Brain v]
    if <<([Color1 v] hue in degrees) [math_greater_than v] [290]> and <([Color1 v] hue in degrees) [math_less_than v] [350]>> then
    print [Pink!] on [Brain v] ▶
    wait (0.1) seconds
    else
    print [Not pink.] on [Brain v] ▶
    wait (0.1) seconds