Ultrasonic ?

I want to use an ultrasonic sensor to drive a set distance how do i go about doing that ?

Assuming you know how to install the sensor and get readings:

  1. Get a reading from the UltraSonic. this will tell you the distance to something in front of the robot
  2. Drive
  3. While driving, continuing to read distances
  4. When the change in distance equals the desired distance, stop driving.

Notes:
a) This only works if there is something within the range of the sensor.
b) You might want to stop driving a little before the desired distance in order for the robot to coast to a stop at the correct distance.
c) If something crosses in front of your robot, that will be a problem.
d) In general, you are better off using encoders to guage distance, and the ultrasonic as a check that you are close to the final destination (for example, in front of the peg).