Optical Sensor#
Introduction#
The V5 Optical Sensor detects the color, brightness, and presence of nearby objects using a combination of an RGB color sensor and proximity sensor. It can also use its built-in LED to illuminate objects for more accurate detection.

Below is a list of available blocks:
set Optical light – Turns the Optical Sensor’s LED on or off.
set Optical light power – Adjusts the brightness of the Optical Sensor’s LED.
Optical found object? – Returns whether the sensor is detecting an object.
Optical detects color? – Returns whether the sensor is detecting a specified color.
Optical brightness – Returns the amount of light reflected from the object as a percent.
Optical hue – Returns the hue value of the detected color.
when Optical – Runs the attached stack when sensor detects or loses an object.
set Optical light#
The set Optical light block turns the Optical Sensor’s LED on or off. This can help increase the sensor’s accuracy when detecting colors.
设定 [Optical 1 v] 灯 [on v]
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
state |
The state to set the LED to:
|
当开始
[Turn on the sensor's LED.]
设定 [Optical 1 v] 灯 [on v]
set Optical light power#
The set Optical light power block sets the brightness of the Optical Sensor’s LED. If the LED’s brightness is set above 0 while it is off, it will automatically turn the LED on.
设定 [Optical 1 v] 灯亮度为 [50]%
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
brightness |
The brightness to set the LED to as a percent. |
当开始
[Turn on the sensor's LED at half brightness.]
设定 [Optical 1 v] 灯亮度为 [50]%
Optical Sensor found object?#
The Optical Sensor found object? block returns a Boolean indicating whether the sensor is detecting an object.
True – The Optical Sensor is detecting an object.
False – The Optical Sensor is not detecting an object.
<[Optical 1 v] 发现对象?>
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
Example
当开始
[Drive forward until an object is found.]
驱动 [向前 v]
等到 <[Optical 1 v] 发现对象?>
驱动停止
Optical Sensor detects color?#
The Optical Sensor detects color? block returns a Boolean indicating whether the sensor is detecting a specified color.
True – The Optical Sensor is detecting the specified color.
False – The Optical Sensor is not detecting the specified color.
Note: The Optical Sensor is looking for hue ranges that match the specified color. For detecting specific hue ranges, see the Optical hue block.
<[Optical 1 v] 测得 [红色 v]?>
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
color |
Which color to look for:
|
Example
当开始
[Drive forward until an object is found.]
驱动 [向前 v]
等到 <[Optical 1 v] 发现对象?>
驱动停止
Optical brightness#
The Optical brightness block returns the amount of light reflected from the object as a percent.
([Optical 1 v] 亮度百分比)
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
Optical hue#
The Optical hue block returns the hue value of the detected color.
This value ranges from 0 to 359 degrees, which correlates to the color wheel:

([Optical 1 v] 色调度数)
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
Example
当开始
[Look for the color pink using hue.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[300] [math_less_than v] ([Optical 1 v] 色调度数) [math_less_than v] [359]> 那么
在屏幕上打印 [This is pink!]▶
否则
在屏幕上打印 [No pink detected!]▶
when Optical#
The when Optical block runs the attached stack whenever the Optical Sensor detects or loses an object.
当 [Optical 1 v] [detects v] 一个对象 :: hat events
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
state |
When the attached stack of blocks will run:
|