Updated Solution
After testing out Joel's code to check the sensor was in order, I found some new sample code which worked to display the distance in inches of a HC SR04 sensor.
// set up variables
int trigpin = 13; // Trig Pin is connected to Arduino pin 13
int echopin = 11; // Echo Pin is connected to Arduino pin 11
// now we need variables which we will be measuring
float pingtime; // Time for ping to travel to target and return
float targetdistance; // Distance from sensor to target
float speedofsound = 776.5; // speed of sound in miles per hour at 77 F
void setup() {
Serial.begin(9600); // Turn on serial port
pinMode(trigpin, OUTPUT); // Sensor trig pin is output
pinMode(echopin, INPUT); // input is reading from echopin
}
void loop() {
digitalWrite(trigpin, LOW);// set trigger pin low
delayMicroseconds(2000); // pause to let signal settle
digitalWrite(trigpin, HIGH); // set trigger pin high
delayMicroseconds(15); // pause in high state, make sure sensor reads
digitalWrite(trigpin, LOW); // bring trigpin back low
pingtime = pulseIn(echopin, HIGH);
// sensor will be sending HIGH pulse, measure pingtime at echopin
// ping time is in microseconds
pingtime = pingtime / 1000000.;
// converts pingtime to seconds because speed of sound is miles per hour
pingtime = pingtime / 3600.;
// converts pingtime to hours
// add a period to make float to avoid int mistakes
targetdistance = speedofsound * pingtime;
// calculates distance in miles traveled by ping
targetdistance = targetdistance / 2;
// accounts for roundtrip of ping to target
targetdistance = targetdistance * 63360.;
// convert target distance to inches
// 63360 inches in a mile
Serial.print("The distance to the target is:");
Serial.print(targetdistance);
Serial.println("inches");
delay(1000);
}