ultrasonic code

hi guys can any one help me with ultrasonic code !!? that i need to read the distance in cm the send it as analog to control motor speed ?? anyone can give me such code thx in advance :)

What have you tried so far?

Have you worked through the examples?

Look here in the Playground for distance sensing. You can probably find the exact code to read your make and model of sensor. Have you got it hooked up and working yet?

Here's an example of controlling the speed and direction of a motor. Have you got it hooked up at all? If not, have a look at this.

Then have a look at if/else to see how you might set various thresholds of distance and have appropriate speeds. Or of course you can go the whole nine yards with pid control but you probably don't want to start there.