ultrasonic distance sensor

can someone provide me some exmple sketching for arduino robot using ultrasonic distance sensor to detect clift and prevent it from falling?

To detect a cliff with ultra sonic sensor, you would need to point it down and detect a change of very short echo to long echo time. This requires constant processing.

You may be better off to use a reflective optical sensor pointing down. You could then use an interrupt to process when the sensor fails to detect object.