NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

bilal_ahmad_21:
my robot is working fine with just one single sonar and using that same old ping library
all i did was calibrating the time of servo movement with the time taken by sonar to take a reading

digitalWrite(trigPin, LOW);                   // Set the trigger pin to low for 2uS

delayMicroseconds(2);
 digitalWrite(trigPin, HIGH);                  // Send a 10uS high to trigger ranging

delayMicroseconds(10);
 digitalWrite(trigPin, LOW);                   // Send pin low again
 int distance = pulseIn(echoPin, HIGH);        // Read in times pulse
 distance= distance/58;  // Calculate distance from time of pulse
 delay(10);                            // Wait 50mS before next ranging

I can see that your robot has problems at times which NewPing would fix. Using the code listed will cause problems. While you don't specifically ask for help, you must be wanting help resolving roblems I see in your video with your robot.

Switching out that code for my NewPing library will allow for faster pings and no long ping timeouts that I can see sometimes with the video of your robot. It doesn't happen often because you have a wall around the area it's in. But, if you didn't have that wall and it was in the wild, it would oddly pause at times. I'm sure you've experienced this as I can see it in your video. NewPing fixes this.

Further, you're not using event-driven programming so your robot is doing nothing when it could be doing something else (for example, multiple ping sensors or different types of sensors at the same time). NewPing has an interrupt-driven ping method that allow you to do other things at the same time you're waiting for a ping echo. For example, with NewPing your sketch could create a ping every 29ms while you rotate the servo. When it received a ping echo it would trigger an interrupt that would turn your robot. There would be no delays in your sketch so more processing could be done without resorting to slowing down the ping rate.

Hope that helps!

Tim