A seller on eBay mistakenly shipped me one of these sensors instead of what I ordered and when I contacted them, they told me to just keep it. Now I have this sensor and I don't want it to go to waste, but I don't know what to use it for. I briefly googled around and saw sensors for parking cars or using two in tandem to make motion tracking, but that's about all I could find. So what other projects are there? Cheers.
Lot of folks use with moving vehicles/robots for detecting & avoiding things like walls.
Hi majhi,
I have used a few of these, usually on a robot/buggy to detect distance from an object, then the buggy makes a turn etc. The program is fairly simple and returns a distance in CM's. They are often mounted on a servo, so the robot can "LOOK" left and right, take readings and move accordingly.
Here's some code:
long scanner(long cm)
{
const int pingPin=2, EchoPin=3;
long duration;
// The SRF005 is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse before to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
pinMode(EchoPin, INPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(2);
digitalWrite(pingPin, LOW);
duration = pulseIn(EchoPin, HIGH);
delay(100);
// convert the time into a distance
// inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
return (cm);
}
//------------------------------------------------------------------
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimetre.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
Regards
Mel.