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.
conjunto [Optical 1 v] luz [encendido v]
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
state |
The state to set the LED to:
|
cuando empezó
[Turn on the sensor's LED.]
conjunto [Optical 1 v] luz [encendido 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.
Establezca la potencia de luz [Optical 1 v] al [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. |
cuando empezó
[Turn on the sensor's LED at half brightness.]
Establezca la potencia de luz [Optical 1 v] al [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] Encontraste un objeto?>
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
Example
cuando empezó
[Drive forward until an object is found.]
unidad [adelante v]
esperar hasta <[Optical 1 v] Encontraste un objeto?>
deja de conducir
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] detecta [rojo v]?>
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
color |
Which color to look for:
|
Example
cuando empezó
[Drive forward until an object is found.]
unidad [adelante v]
esperar hasta <[Optical 1 v] Encontraste un objeto?>
deja de conducir
Optical brightness#
The Optical brightness block returns the amount of light reflected from the object as a percent.
([Optical 1 v] brillo en %)
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] tono en grados)
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
Example
cuando empezó
[Look for the color pink using hue.]
para siempre
pantalla clara
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <[300] [math_less_than v] ([Optical 1 v] tono en grados) [math_less_than v] [359]> entonces
imprimir [This is pink!] en la pantalla ▶
demás
imprimir [No pink detected!] en la pantalla ▶
when Optical#
The when Optical block runs the attached stack whenever the Optical Sensor detects or loses an object.
cuando [Optical 1 v] [detects v] un objeto :: hat events
Parameters |
Description |
|---|---|
device |
Which Optical Sensor to use, configured in the Devices window. |
state |
When the attached stack of blocks will run:
|