# Touch Sensor

\
The FTC touch sensor is simple but effective. It detects whether the sensor has been pressed or not. When it button has been depressed a circuit is completed, registering it as a touch.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdHtShNJJHNyKZS7_F70I_h63-dUugVS1pO69UlZA7_MXV9bPL5ID46laltgy0z0FdHqh9pfgPqOFO4joFal0KnK1NFifmO6fPLVFBtXZ9m3lJGtFrSCZVti4x1Y_JMujaGu25cWaUzU74xvtNRZRjUyoc?key=zSFYHlrpLkUmVPkShIlfgQ)

\ <br>

The range sensor is used for obstacle avoidance and as a limit switch. When attached to the outside of the robot, when the touch sensor detects a touch, you know the robot has collided with something and should reverse. Limit switches are devices used to prevent robot parts from moving beyond a certain point. For example, if your robot has a robotic arm, you don’t want the robot arm dragging on the ground. To ensure that doesn’t happen you install a touch sensor at certain joints. If the arm has moved below a certain point, it will touch the touch sensor and signal that the arm has been depressed too far. An automated response can then be sent to raise the arm back up to a safe level. <br>

Programming using the sensor is easy. Simply use the block getDistance

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXftRsnAQ-erIAseQ0fhqrLPLXjDZxlXoh5efIKSHKSUjqNZMd-M5Bf8503piDIYy-C2AdyqZd8sFIwJQ101loHSJgLNdK_KZT-8HT7kAqvMUZb9F_iJUyGyNPHb1TXgm6dANtG1tEbCn8uZRed3pSFy1sxV?key=zSFYHlrpLkUmVPkShIlfgQ)

to determine the distance of the closest object in front of the distance sensor. You can select the units the distance is recorded in. <br>

Here is how the touch sensor can be used for touch avoidance.&#x20;

Create a simple logic statement:

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfoo8yBvC1yc9ImBI5mnsvTVBHkiVwISDY2j9OoRakxSeIuqMjArcYS1Bi9hea_XDHpGIaJuMcxlthxB7o7gMPfZEXQxqR1iNyiUKoQQZgSK0BuuFFgb7oAzHfyIQpzyq21Ho5XDJ0yCLhOpCPM_So4niMu?key=zSFYHlrpLkUmVPkShIlfgQ)

Then when collision is detected, reverse the robot by reverse motor power for 1 second.&#x20;

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdP5mIVFDAmEHcJ7KRRyJ-_npDJV7uGO9qV82mqqJjtWAqaNxGSAcH8uWanM7hWj4zIe7_0cRZAeiIwtKDWLFp6qVh9JgXPwaCPtr25pV0H0qx8d-AMAoJ1OZ_a3UAb4UMg-MmEgYuhlKipaglklyVfj_j8?key=zSFYHlrpLkUmVPkShIlfgQ)

Put this within a for loop for continuous detection.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcSAr8hpLdK66od3M4Jbdq3kZOmm4WXSuASogPCy5PKqyqAHjY7_WRQTSVwtSw30u0S850H9CcK7AdEO4uT__nF46EGUqIa3HtktXGC8MsR0zD7iqnUJUZuB9GK-po31fugcHAFPZk0P0h92DMvpae1uY0Z?key=zSFYHlrpLkUmVPkShIlfgQ)

And there you have an anti collision algorithm!

Touch sensors can prove to be useful in certain situations. Be creative!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vrs-guidebook-2nd-edition.gitbook.io/vrs-guidebook-2nd-edition/programming/basic-lessons/touch-sensor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
