Main Content


Read rotation rate from gyroscopic sensor

Add-On Required: This feature requires the MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware add-on.



rotationrate = readRotationRate(mygyrosensor) reads the rate of rotation of the sensor, and returns the measurement in degrees per second.


collapse all

Measure rate of rotation, degrees per second, using 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 current rate of rotation, in degrees per second.

rate = readRotationRate(mygyrosensor)
ans =


The gyro sensor is rotating at 12 degrees per second.

Input Arguments

collapse all

Connection to gyroscopic sensor, specified as a string that represents the object created using gyroSensor.

Example: mygyrosensor

Data Types: double

Output Arguments

collapse all

The rate of rotation, returned as an int32 value, from -440 to 440 degrees per second.