You might read http://arduino.cc/en/Reference/PulseIn and add the timeout variable to see if the sensor times out (or not).