# Range Sensor

The REV Color/Range sensor is a very versatile device used in robotics, particularly in FTC. It combines both color sensing and proximity detection capabilities.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcfJLPUCGMXMouFQrAmoLAgeL4EtbaO4G46gHxwrx-XGSPthZqvc7hYSLkLGdlFw4qUyL2A9tnVp1pTYYmn0TlckwEErRb3G_5ar8J7Vyy-rkuX0BW-yl6DqvystHnMe0_BJhsJe-_RB34jfwdB39b5aEmW?key=KJbLi0MMTTiZUJ6tFjLniw)

This section will cover the proximity detection aspect of the sensor. The distance sensor works by bouncing infrared light off an object and using the time between sending and receiving the light to calculate the distance between the sensor and the object.&#x20;

The distance sensor is useful for both object detection and obstacle avoidance. The distance sensor can indicate if an obstacle is close or not to the robot, allowing for the robot to react accordingly. The range sensor can also be attached to the intake of the robot, allowing the robot to sense if an object has been collected or not.&#x20;

Using the sensor is easy. Simply use the block getDistance

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXepwudCl9EtiuPM0hgF8n2Vs3CM8hy3fNbYvXwXqUSbcoZ8pOiHBr_nJp2AsYjta2WuZhmbw-m8W_byF63RpsT4LvSyYG68Pc_mQ0cpnoYZVibDp_aL6BWTOKzpVJw4F--EnmXCecW6FIuISUHIP0pHjHEq?key=KJbLi0MMTTiZUJ6tFjLniw)

to determine the distance of the closest object in front of the distance sensor. You can select the units the distance is recorded in.&#x20;

This is often used in logic statements to check if the robot has encountered an obstacle. \
For example, if the range sensor detects if there is an object within 20cm from the front of the robot, the robot will move backwards for 1 second.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfcXTN30CPDnqtu92ObrtnDgoW6DQM7rJDt7-bp5hz8h9aB9gIw38b_ZxUuCqxQdwm0wcCi-fS1j_a5bbsttzKXhpUQH-m-D8D_or30rsoz6V_Wqz8aNIuC_kON2q6khpQaxXS3Z6_uXbsPWKo1TztkZMk?key=KJbLi0MMTTiZUJ6tFjLniw)

Putting this within a for loop for continuous detection

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcZvl9YoFjeJU-NWuQQDhWviTUqnk_AN1QEePFZ6Pv9Lwu9Gj4aNz0PzIeq9e2DialBiiNULcvpyBbGCtZKVUdvwD8ic7QBVwUmLJw3e0bXDIW7OkGI6pNfRwsHGMT9SJLtUB57MaX4x8jRha1X16kGKBoC?key=KJbLi0MMTTiZUJ6tFjLniw)

You get a simple anti collision algorithm!

The range sensor can prove to have numerous uses if you are creative! Several examples are present in this book. Feel free to experiment. <br>


---

# 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/range-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.
