Generally, you need to wait after reading an ultrasonic sensor, so that any echoes die away. Your code is pinging continuously.
Generally, you need to wait after reading an ultrasonic sensor, so that any echoes die away. Your code is pinging continuously.