Gyro sensor and geometric figures

Preparing For This Tutorial:

The LEGO Mindstorm EV3 Robot that coincides with this tutorial comes from building specific sections found in the LEGO Mindstorm Education Core Set building instructions. You will need to build the main body for the robot (I’ll refer to as the Base Unit), plus gyro sensor.

Time constraints:

  • starting from 45 min - single lesson


Create a program that will make the robot run around the circumference of: an equilateral triangle, a square,a pentagon and other polygons.


There are three special names given to triangles that tell how many sides (or angles) are equal.

  • Equilateral Triangle - three equal sides, three equal angles, always 60°

  • Isosceles Triangle - two equal sides, two equal angles

  • Scalene Triangle - no equal sides, no equal angles

In any triangle the three angles always add to 180°.

Two Angles are Supplementary when they add up to 180 degrees. Notice that together they make a straight angle.

These two angles (150° and 30°) are Supplementary Angles, because they add up to 180°:

A polygon is regular when all angles are equal and all sides are equal (otherwise it is “irregular”).

This is a regular pentagon (a 5-sided polygon).

The Exterior Angle is the angle between any side of a shape, and a line extended from the next side.

The Interior Angle and Exterior Angle are measured from the same line, so they add up to 180° (they are supplementary).

Short help on programming

Commands/functions needed for the exercise

Commands necessary to move

#!/usr/bin/env python3

from ev3dev2.motor import MoveTank, OUTPUT_B, OUTPUT_C




Import necessary library and create a new instance of the class and assigns this object to the local variable gy

#!/usr/bin/env python3

from import GyroSensor

gy = GyroSensor()

Set mode of gyro sensor

#!/usr/bin/env python3

 gy.mode = 'GYRO-ANG'

 Read the value from gyro sensor


Example solution

#Create a program to make the robot move straight and then turn 90 degrees.

# Import of necessary libraries

#!/usr/bin/env python3

from ev3dev2.motor import LargeMotor, MoveTank, OUTPUT_B, OUTPUT_C

from import GyroSensor

from time import sleep

#Connect two large motors to port B and port C


#Plug a gyro sensor into any sensor port

gy = GyroSensor()

#Set mode of gyro sensor

gy.mode = 'GYRO-ANG'

#read the value from gyro sensor




#do the loop while condition is true

while angle-start_angle<90:


  #you are able to see the results on the screen


Next Section - Museum at night