Ping just doesn’t detect an
Ping just doesn’t detect an obstacle like an IR proximity sensor ,it detects the distance between the obstacle and itself. The Ultrasonic sensor output gives a square pulse,having time period equivalent to the distance of the object in front of it. Use pulsein command to get the time in microseconds.
nice see some from india here
it produces square pulse of 8 cycles the sensor have the range less than 2m.i think your idea will work but for giving buzzer in particular distance like object with in 20cm use microcontroller, other wise buzzer will sound for the object within range of the sensor.