Mobile Robotic arm Programming

I built a robotic claw actuated by a 9g micro servo and a HC-SR04 Ultrasonic sensor is mounted on it aimed at the middle of the two 'fingers'.
I want the claw to open when an object comes 15cm or lesser length towards the gripper, and I want it to close when the object comes 13cm or lesser length towards the gripper.
The micro servo operates in 90 angles.
Can anyone plz give me a code capable of doing the above task?
:slight_smile:
Thnx