This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Read color of object in front of color sensor


color = readColor(mycolorsensor)



color = readColor(mycolorsensor) reads the color of an object in front of the color sensor, and returns it as a string, such as red, green, or blue.


collapse all

Read the color of an object in front of 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 =


Input Arguments

collapse all

Connection to a color sensor, specified as a string that represents the object created using colorSensor.

Example: mycolorsensor

Data Types: char

Output Arguments

collapse all

The name of the color read by the color sensor, returned as a string.