Trouble with obstacle avoiding robot

Cactusface:
Hi,
Why use Ping.h? can't understand it, the basic code is so simple and for me works everytime.

Here's some code cut from one of my programs:

ong scanner(long cm)

{
const int pingPin=7, EchoPin=8;
long duration;

// The SRF005/HC-SR04 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 centimeter.
// 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;
}

void Radar()
{
Halt();
BackOff();
Lturn();
sound(2200,20);
Halt();
A=scanner(cm);
delay(100);
Rturn();
Rturn();
sound(2200,20);
Halt();
B=scanner(cm);
delay(100);
Lturn();
delay(50);

if (A>B) 
{
	Lturn();  //Then turn left
	A=0; 
}
else  
{
	Rturn();  //Then turn right
	B = 0;
}

}




By the way the L329/L398 are poor drivers as you lose power (2v+) on the output transistors use something with FET outputs, more power... You have called the motors A & B that's fine so why not call the pins MA- MA+ makes sense!

Hope it helps, regards. (see www.melsaunders.co.uk for my bots)

Mel.

Thanks for the response. I used NewPing because it looked simple enough, was recommended on Arduino's page for ultrasonic sensors, and this is really only my second arduino project. I actually had your page open from another related post on these forums so I'll take a look around. I'll also take a look at the regular ping library. Perhaps there's an issue with NewPing that is returning some of the strange readings.