Sharp Infra Red distance sensors.
There are a number of different sensors but they are all used in the same way. The difference between them is the usable range over which they can detect objects. The devices work by shining a beam of light which is reflected back from an object. The further away the object is then the more it displaces the light to the sides. Therefore: you will notice that the devices which can detect further distances are physically larger because the 'eye' which sees the reflection needs to be further away from the transmitter. Equally the transmitter needs to be more powerful and is therefore larger.
Because these devices uses a beam of light then they are not very good at detecting thin objects - like chair legs. This happens because the beam of light may move from one side of the leg to the other and so therefore it misses the fact that the leg is there. For a less precise detector you should consider using a sonar.
The devices output a voltage and so should be connected be to an ADC pin and use the +5V regulated supply to power them. A word of caution: these devices are inherently noisy and require spikes of current. The noise can be reduced by connecting the black casing to ground (yes - it looks like plastic but it is actually conductive). If your robot has a metal shell then bolt the sensor to the shell and connect the shell to ground. The current spikes can be minimised by fitting a capacitor of around 10uF close to the device - preferably by soldering an SMD capacitor into the device itself.
You will still find some spikes in the readings and so, if these spikes confuse your robot, then you should consider writing a low pass filter in software to filter out these spikes. But a word of caution: that spike may actually be correct ie something has suddenly come into view.
The range of devices we support are as follows:-
GP2D12 This measures between 10cm and 80cm
GP2D120 This measures between 4cm and 30cm
GP2D15 This measures between 10cm and 80cm
GP2Y0A02YK This measures between 20cm and 150cm
GPY0A21YK This measures between 4cm and 30cm
GP2Y0A02YK0F This measures 20cm to 150cm
GP2Y0A710K0F This measures 100cm to 550cm
GP2Y0A700K0F This measures 100cm to 550cm
Note that the larger the maximum distance then the more peak current these devices will require. It is common for them to require a peak current of 0.3 amps !
Assuming you have called your sensor 'myDistance' in Project Designer then it can be accessed as follows:-
DISTANCE_TYPE cm = myDistance.getDistance();
cout << "Distance=" << cm;
Or dumped to the standard out destination using:-
cout << myDistance;
- dump - Dump the last read sensor values to the standard output device.
- dumpTo - Dump the contents of the sensor to the specified output stream.
- getDistance - Returns the distance in whole cm detected by the sensor during the last read().
- getTimeLastRead - Returns the value of the clock at the time when the sensor was last read.
- read - Read the sensor and store its current values. Returns TRUE if the sensor has been read successfully, or FALSE if the sensor is busy in which case the read values are unchanged.