WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Devantech SRF05 sonar

Devantech SRF05 sonar.
sonar srf 05.jpg
The sonar can be connected to any I/O pin but requires a +5v regulated supply. The device can be operated in two different modes. We use 'Mode 2' since that only requires a single pin to drive it - and so you must connect the 'Mode' pin on the board to the ground pin. The sonar can measure distances up to 430 cm.
Example
Assuming you have called your sensor 'myDistance' in Project Designer then it can be accessed as follows:-
myDistance.read();
DISTANCE_TYPE cm = myDistance.getDistance();
cout << "Distance=" << cm;
Or dumped to the standard out destination using:-
cout << myDistance;
According to the datasheet you should not read the sensor within 50mS of taking the previous reading. Otherwise you will get ghost echoes from the previous reading. This library will automatically detect if that happens and, in the event, will return the previous reading. If you are using more than one sonar then you will need to manually add delays to stop this sonar from receiving ghost echoes from the other sonars.
Function Summary

Valid XHTML 1.0 Transitional