sync ping sensor with servo for obsticle avoidance

Greetings all you young wise ones.

I am just starting to try and use the arduino mega, so I decided that I would take a rc car and make it into a robot of sorts. basically I want the arduino to control the car to avoid obstacles. The car has a dc motor for the drive and a servo for the steering. I mounted a bracket with a servo and a ping sensor attached to the servo. The problem I hope someone can help me with, is getting the ping sensor to sync with the servo. Meaning; I want the ping sensor to work every time the servo stops. The attached is the code that I have been working on. Please forgive me if I am posting in the wrong area or doing something wrong in reference to this site. I am not only new to Arduino. I am also new to this site. Thank You

RunawayRobot 6_ino.rar (1.93 KB)