Using the Gyro Sensor

The Gyro Sensor detects rotational motion. If you rotate the Gyro Sensor in the direction of the arrows on the case of the sensor, the sensor can detect the rate of rotation in degrees per second. You can use the rotation rate to detect, for example, when a part of your robot is turning, or when your robot is falling over.

In addition, the Gyro Sensor keeps track of the total rotation angle in degrees. You can use this rotation angle to detect, for example, how far your robot has turned.
Gyro Sensor Data
The Gyro Sensor can give the following data:
DataTypeNotes
Angle NumericRotation angle in degrees.
Measured from the last reset. Reset with the Reset mode of the Gyro Sensor block.
Rate NumericRotation rate in degrees per second.
Tips and Tricks
The Gyro Sensor can only detect motion around a single axis of rotation. This direction is indicated by the arrows on the case of the sensor. Make sure you attach the sensor to your robot in the correct orientation to measure rotation in the desired direction.
The Angle and Rate can both be either positive or negative. Clockwise rotation is positive and counter-clockwise is negative.
When connecting the Gyro Sensor to your EV3 Brick, you must hold it completely still in order to minimize “drifting”
The Angle may “drift” over time and become less accurate. For best results, reset the angle using the Reset mode of the Gyro Sensor block before every motion that you want to measure the angle of.
The Motor Rotation sensor can also measure rotation in degrees, but only for the rotating part of a motor.
Examples Using the Gyro Sensor
Examples of how you can use the Gyro Sensor in your program are shown below.
Example 1: Turn by a Specified Angle
This program makes a robot turn 90 degrees to the left. It uses the Wait block with the Gyro Sensor - Change – Angle mode to wait for the rotation angle to change by 90 degrees.
Tips and Tricks
Tip: Because the program above uses the Change mode of the Wait block, it measures the change in angle relative to the start of the Wait Block. Therefore, it is not necessary to reset the Gyro Sensor before the movement.
Example 2: Display a Rotation Rate Meter
This program has the robot display the rotation rate graphically. The Gyro Sensor block measures the numeric value of the rotation rate, and this value is used to vary the width of a rectangle on the EV3 Display.
Gyro Sensor Blocks and Modes
The table below shows the programming blocks and modes that you can use with the Gyro Sensor.
BlockModeUse
Wait Gyro Sensor - CompareWait for the rotation angle or rate to reach a certain value.
WaitGyro Sensor - ChangeWait for the rotation angle or rate to change by a certain amount.
Loop Gyro SensorRepeat a sequence of blocks until the rotation angle or rate reaches a certain value.
Switch Gyro SensorChoose between two sequences of blocks based on the rotation angle or rate.
Gyro SensorMeasureMeasure the rotation angle and/or rate, and get the result on a Numeric data wire.
Gyro SensorCompareCompare the rotation angle or rate to a threshold, and get the result on a Logic data wire.
Gyro SensorResetReset the rotation angle to zero.
Data LoggingGyro Angle
Gyro Rate
See Data Logging.
Gyro
Quick links