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 — Sets the brightness of the Color Sensor’s light.
Color found an object? — Returns whether any object is detected.
Color detects color? — Returns whether a specific color is detected.
Color color name — Returns the name of the detected color.
Color brightness — Returns detected brightness as a percentage.
Color hue — Returns the hue angle of the detected color.
set Color light#
The set Color light block sets the brightness of the Color Sensor’s light.
设定 [Color 1 v] 灯亮为 (50)%
Parameters |
Description |
|---|---|
color sensor |
Which Color Sensor’s light brightness to set, configured in the Devices window. |
brightness |
The brightness of the light from 0 to 100 as a percent. |
Example
当开始
[Light up the Color Sensor dimmer.]
设定 [Color 1 v] 灯亮为 (25)%
等待 (2) 秒
[Light up the Color Sensor brighter.]
设定 [Color 1 v] 灯亮为 (100)%
Color found an object?#
The Color found an object block returns a Boolean indicating 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.
<[Color 1 v] 发现对象?>
Parameters |
Description |
|---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
当开始
[Print a different message when an object is in front of the Color Sensor.]
永久循环
在 [Brain v] 设定光标至 (1) 行 (1) 列
如果 <[Color 1 v] 发现对象?> 那么
在 [Brain v] ▶上打印 [Object detected]
否则
在 [Brain v] ▶上打印 [Nothing detected]
结束
清除 [Brain v] 第 (1) 行
Color detects color?#
The Color detects color block returns a Boolean indicating 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.
<[Color 1 v] 测得 [红色 v]?>
Parameters |
Description |
|---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
color |
Which color to check for:
|
Example
当开始
[Turn until the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
Color color name#
The Color color name block returns the name of the color detected by the Color Sensor.
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.
([Color 1 v] 颜色)
Parameters |
Description |
|---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
当开始
[Stop and print when the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
在 [Brain v] 上打印 ([Color 1 v] 颜色) ◀ 并设定光标为下一行
Color brightness#
The Color brightness block returns the amount of light detected by the Color Sensor in a range from 0% to 100%.
([Color 1 v] 亮度百分比)
Parameters |
Description |
|---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
当开始
[Stop and print the brightness when the Color Sensor detects green.]
[右 v] 转
等到 <[Color 1 v] 测得 [绿色 v]?>
驱动停止
在 [Brain v] 上打印 ([Color 1 v] 亮度百分比) ◀ 并设定光标为下一行
Color hue#
The Color hue block returns the hue value of the color detected by the Color Sensor.
Hue values range from 0 to 359 degrees, corresponding to positions on the color wheel shown below.

([Color 1 v] 色调度数)
Parameters |
Description |
|---|---|
color sensor |
Which Color Sensor to use, configured in the Devices window. |
Example
当开始
[Print when the Color Sensor detects pink.]
永久循环
清除 [Brain v] 所有行
在 [Brain v] 设定光标至 (1) 行 (1) 列
如果 <<([Color 1 v] 色调度数) [math_greater_than v] [290]> 与 <([Color 1 v] 色调度数) [math_less_than v] [350]>> 那么
在 [Brain v] ▶上打印 [Pink!]
等待 (0.1) 秒
否则
在 [Brain v] ▶上打印 [Not pink.]
等待 (0.1) 秒