Your code works fine for me. I guess a loose connection could the the source of the problem. But, it could also be that you're trying to get a ping that's just too far away. These sensors really don't work all the way out to 400 or 500cm. They seem to work okay to about 200cm for most, but I have some sensors that won't read anything consistently beyond around 75cm. This is the fault of the sensors, not the library as the same thing happens with other libraries or with no library at all. Try putting something 50cm away from the sensor and see what happens then. It's just suspicious that it stops working around 200cm and then in your next test all the results are within 200cm. Maybe it would work without you holding the sensor if all the readings were <50cm? But, if it is a lose connection, that could also be why it's crashing after a few minutes, it's simply shorting out. BTW, I've *never* got a zero reading that wasn't for a logical reason and I've *never* had any of my Arduino or Teensy 2.0 crash while using the NewPing library. And, I've sometimes ran them for several hours or even overnight without a single issue.
Yeah, as i say, it was all due to loose connections. I just got everything soldered, and now i get 0 only when its out of range. Both tests you see above where done in the same room, where i should get no zeros at all since its pretty small.
I guess the "arduino stops working" would be due to some data generated by the loose connection that would cause an overflow.
Everything working pretty much perfect right now!