While surfing on the Internet, we found a nice little sensor: an optical rangefinder built by Sharp. Robotic specialists know it well, it's the most well known sensor to detect obstacles. In our selection of products, we currently don't offer a rangefinder sensor (telemeter). As an example, we are going to show you today how you could interface analog sensors of this type thanks to a Yoctopuce module.
This small infrared sensor is composed of two parts: a led infrared light emitter, and a receiver measuring the reflection. The subtlety of this model is that it is able to automatically operate a triangulation to determine the distance of the obstacle, rather than simply measuring the reflection. The intensity of the reflection would vary too much depending on the color of the obstacle to be able to deduce a distance.
Analog Distance Sensor 20-150cm (Sharp GP2Y0A02YK0F)
The sensor needs a 5V power supply, and returns on the 3rd wire a voltage inversely proportional to the distance of the obstacle. For this example, we are therefore going to use a Yocto-Volt, our very multipurpose voltmeter. Using the solder pads on the Yocto-Volt just behind the Micro-USB socket, we get the 5V supply directly from the USB bus. We put the 3rd sensor wire in the designed terminal block, and the hardware is ready: we have created a tiny USB telemeter.
We still need to compute the distance. There are three variants of the sensor, depending on the measuring range you need:
- 4cm to 40 cm (model GP2Y0A41SK0F)
- 10cm to 80cm (model GP2Y0A21YK0F)
- 20cm to 150cm (model GP2Y0A02YK0F)
These three models are in stock for example on the Farnell (or Pololu) site for about 10 Euros, which makes it a very cheap sensor to measure a distance.
In our short example, we have selected the model measuring up to 1m50. According to the sensor datasheet, we obtain the distance (in centimeters) by dividing 60 by the voltage on the sensor measure output. For example, if the voltage is 1V, the obstacle is 60cm away. If the voltage is 2V, the obstacle is 30cm away. Here is the Python code of a telemeter built with a Yoctopuce module:
sys.exit('No Yocto-Volt found (check USB cable)')
voltage = dcVoltageSensor.get_currentValue()
if voltage <= 0:
voltage = 0.001
distanceInCm = 60 / voltage;
print("Distance: %3.2f cm (%3.2f V) " % (distanceInCm,voltage))
That's it! We only need to transform this telemeter into something more useful. For example, we can equip a garage with a beacon signaling when a vehicle gets close to the back wall.
This project can be used as a car park assistant
To do this, we add a Yocto-PowerLed and a few lines of code to change the led color and make it flash, depending on the distance of the approaching car. Here is the result in a video:
The complete code including management of the Yocto-PowerLed is available here. If you are interested, don't wait for too long to buy your rangefinder sensor: Sharp decided to stop producing it. If you are not in a hurry or if your are looking for a solution allowing you to perform longer or more precise measures, contact us: we are currently thinking about providing a telemeter module, more professional than the experiment of this week. Stay tuned...