Help with Ultrasonic panning progam

I’m build a autonomous robot, Right now I have hooked a servo to an ultrasonic sensor and have it above my robot, i want it to be able to pan around and take about 5 “senses” and go toward the greatest, one but i don’t know how. Right now it’s just taking 2 “senses” and witch ever is greater it goes toward that side, i can advoid objects but it doesn’t work the greatest. Any help would be apprecited thanks