Create connection to gyroscopic sensor


mygyrosensor = gyroSensor(myev3)
mygyrosensor = gyroSensor(myev3,inputport)



mygyrosensor = gyroSensor(myev3) creates a connection to a gyroscopic sensor. You can use this connection with the functions listed in Object Functions to measure the rotation rate or rotation angle of the sensor, and reset the rotation rate measurement to zero.

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


mygyrosensor = gyroSensor(myev3,inputport) creates a connection to a gyroscopic sensor that uses a specific EV3 input port.


collapse all

Get rotation measurements from a gyroscopic 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 gyroscopic sensor called mygyrosensor.

mygyrosensor = gyroSensor(myev3)
mygyrosensor = 

  gyroSensor with properties:

    InputPort: 2

Measure the rotation, in degrees, since the creation of the connection to the sensor.

angle = readRotationAngle(mygyrosensor)
ans =


The sensor has rotated 59 degrees clockwise.

Reset the measurement to zero.


Measure the current rate of rotation, in degrees per second.

rate = readRotationRate(mygyrosensor)
ans =


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 gyroscopic sensor, returned as an object handle.