Here is the code that I normally use:
#include <NewPing.h>
#define TRIGGER_PIN 12
#define ECHO_PIN 13
#define MAX_DISTANCE 200 // In Centimeters (200cm = 78.7") It will not keep waiting for a return if past this value
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(9600);
}
void loop() {
float uS = sonar.ping_median(5);
Serial.print(uS / US_ROUNDTRIP_IN);
Serial.print("a");
}