How to check if the touch sensor is pressed? Pro Preview

What is the Touch Sensor and how to program it?

To access the full video please subscribe to


  • #1626
  • 04 Jun 2020

Touch Sensor

To put it simply, a touch sensor is an electrical switch similar to a light switch that closes an electrical circuit which has electrical current flowing through it.

Programming a Touch Sensor

In order to check if the sensor is pressed, we need to tell the program which port the sensor is connected to. This is done via the "TouchSensor()" and we enter the port inside the brackets.

The sensor ports are as follows:

  • Port.S1 for port one;
  • Port.S2 for port two;
  • Port.S3 for port three;
  • Port.S4 for port four;

After we enter the port where the sensor is connected, we can use the "pressed()" command to check if the sensor is pressed:


The "pressed()" command serves as the question "Is the button pressed?" and returns an answer of "True" or "False".

⚠️ The "pressed()" command does not initiate any sort of action in the robot. This command asks the sensor for its state a given moment and receives information about the state of the sensor.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Python with LEGO Mindstorms EV3 - Level 2
  • 39
  • 19:58
  • 93
Image for Lesson 1 - Security system.
  • 5
  • 5
  • 10
  • 3d_rotation 1