This GP2Y0A21 sensor from Sharp can be used to detect objects within the range 10cm to 80cm. The sensor senses for objects ahead of it and outputs an analog voltage corresponding to the distance between the sensor and the object. You can easily read this signal from the ADC for an Arduino/Raspberry Pi or a Microcontroller and get the distance of the object. This Sharp sensor is great to add obstacle avoidance or motion sensing to your robot or any other project. The sensor comes with a compatible 3 pin JST 3-pin connector with crimped wires. Since it is a very popular distance sensor, sample codes, tutorials and libraries for Arduino/Raspberry Pi and popular microcontroller are readily available.