HELP a beginner, sensor controlled DC motor code

I'm sorry if this is the wrong section, but I'm new to this and need some help . I only have experience with labview for controls. Does anyone have examples of code for controlling a motor with a distance sensor? Mine needs to basically speed up if someone is close and maintain 10 ft distance from someone. Thanks

What you need is a motor driver, and control it with pwm.

You also need a distance sensor, which might return a value to a analog pin (0-1023) you could then use the map() function to calculate how much you want it to speed up, compared to the distance measured.

If you need a more detailed description on how to do it, you need to post more information about exactly what hardware you got.

I have a Maxbotix ultrasonic sensor with a conversion factor to get the voltage to feet. the goal is to keep a car-type thing 10 feet away from a person. the motor is a 17V DC motor and I'd like to get it going as fast as possible. I have a motor controller I think, or else Ill just make one according to the examples. I really have no knowledge of JAVA, just C++ and labview, so sample code of how inputs and outputs work in a similar case would probably be the most useful for me to learn how to do all of this. Thanks again!

Before you start thinking about actual softwaare, you need to give some thought as to how a simple sonar ranger is going to distinguish a person from other objects in the environment. People tend to be squishy, and not good at returning ultrasound echoes, particularly at 3m range.

it’s already been tested

So you've got the sonar working and you know C. What's the problem?

If the sensor is outputting 0-5V just use AnalogRead (http://arduino.cc/en/Reference/AnalogRead) to read how far away things are (fiddle with the numbers to get the wanted output), and use the map (http://arduino.cc/en/Reference/Map) function to get it scaled to something you can use for your pwm (http://arduino.cc/en/Reference/AnalogWrite) output for the h-bridge motor driver.

That's just what I was looking for. Thank you very much.

I think if you'd read reply #1, all that information was there.

cool dude.