Skip to content
02. Devices > Optical Sensor

Optical Sensor

Edit This Page
optical sensor sketch

The V5 Optical Sensor is a combination of an ambient light, color, proximity, and gesture sensor. Optical sensors report data about the light intensity, color, and proximity of a single point within their field of view. The sensor is also able to detect hand gestures in four directions.

Because of their color sensing capabilities, Optical Sensors are most often used in sorting mechanisms.

Creating an Optical Sensor

Using the Peripherals struct passed to our main function, we can create an Optical Sensor from any one of the 21 SmartPort fields on it.

{...}use vexide::prelude::*;
#[vexide::main]async fn main(peripherals: Peripherals) { let mut sensor = OpticalSensor::new(peripherals.port_1);
Create an Optical Sensor on port 1.
}