Create connection to color sensor


mycolorsensor = colorSensor(myev3)
mycolorsensor = colorSensor(myev3,inputport)



mycolorsensor = colorSensor(myev3) creates a connection to a color sensor. You can use this connection with the functions listed in Object Functions to read colors and measure light intensity.

If multiple color sensors are attached to the EV3 brick, this function chooses the sensor that is attached to the EV3 input port with the lowest number.


mycolorsensor = colorSensor(myev3,inputport) creates a connection to a color sensor that uses a specific EV3 input port.


collapse all

Read the color and ambient light intensity from a color sensor.

Create a connection to the EV3 brick called myev3.

myev3 = legoev3
myev3 = 

  legoev3 with properties:

      FirmwareVersion: 'V1.03E'
           HardwareID: []
            IPAddress: []
    CommunicationType: 'USB'
         BatteryLevel: 100
     ConnectedSensors: {'touch'  'gyro'  'color'  'sonic'}

The sensor appears in the list of connected sensors.

Create a connection to the color sensor.

mycolorsensor = colorSensor(myev3)
mycolorsensor = 

  colorSensor with properties:

    InputPort: 3

Read the color in front of the color sensor.

color = readColor(mycolorsensor)
color =


Read the relative intensity of the ambient light that reaches the color sensor. If not specified, the default mode is 'ambient'.

intensity = readLightIntensity(mycolorsensor)
intensity =


Read the relative intensity of the LED light that a nearby object reflects back to the color sensor.

intensity = readLightIntensity(mycolorsensor,'reflected')
intensity =


Input Arguments

collapse all

Connection to EV3 brick, specified as a string that represents the object created using legoev3.

Example: myev3

Data Types: char

Number of the EV3 input port that the sensor uses, specified as a double.

Example: 1

Data Types: double

Output Arguments

collapse all

Connection to color sensor, returned as an object handle.