Main Content

NXT Gyro Sensor

Measure rate of rotation of HiTechnic NXT gyro sensor

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


Simulink® Support Package for LEGO® MINDSTORMS® EV3 Hardware / NXT Sensors

  • NXT Gyro Sensor block


The NXT Gyro Sensor block measures rate of rotation (yaw) along the single axis of the HiTechnic NXT Gyro Sensor (NGY1044) connected to LEGO MINDSTORMS EV3 brick. This yaw is indicated by a circle above the vertical axis in the image on the left, and by a double-arrow in the image on the right. Before using this sensor for precise measurements, use the offset value to remove small positive or negative bias in the output values, as described in the example below. For more information on NXT Gyro Sensor NGY1044, refer to its datasheet.

During simulations without hardware, this block emits zeros. See Block Produces Zeros or Does Nothing in Simulation.

Calibrate the Gyro Sensor

Use the NXT Gyro Sensor block to perform zero-calibration for the gyro sensor.

  1. Open the legoev3nxtlib block library and copy the NXT Gyro Sensor block to a new model.

  2. Open the legoev3lib block library and copy the Display block to the same model and connect these blocks.

  3. Prepare and run the model on the EV3 brick as described in Run Model on EV3 Hardware. On the LCD display of the EV3 brick, observe any bias in the measurement values from the gyro sensor.

  4. Double-click the NXT Gyro Sensor block. In the block mask that opens, increase or decrease the offset value to reduce the bias.

  5. Save the changes to your model and run the model again. Change the offset value until the bias is nearly zero.


EV3 brick input port number

Select the EV3 sensor port to which the sensor is connected. Avoid assigning multiple devices to the same port. The options are 1, 2, 3, or 4.

Output mode

Select the type of rotation data to output:

  • Rotation rate (-360 to 360) outputs the rate of rotation in degrees per second. When this option is selected, the block displays the Offset parameter.

  • Raw A/D (1023 to 0) outputs the rate of rotation in raw analog-to-digital values per second. When this option is selected, the block hides the Offset parameter.

Sample time

Specify how often the block reads sensor values. This value defaults to 0.1. Shorter sample times, such as 0.01, may produce unreliable measurements.

Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.

Version History

Introduced in R2018a