Need help programming a DC motor to go preset distances and then returning

Hello, I need help coding a project of mine. I'm using an Arduino Mega 2560, a Monster Moto shield from SparkFun, and a Linear Potentiometer (I'm pretty set on using a Linear POT so no other suggestions please). I am decent with coding Arduino but not great by any means.

I need my DC motor to run until it has reached a specified distance (not specified time, I need extreme accuracy) and then stop. It would be a bonus if someone could tell me how to get it to return to its starting position. Thanks for your time if you decide to help me. Ask me questions if you need to know more info to help!

Hello, I need help coding a project of mine.

Do you need help with your project or do you expect someone to write it for you?

If the former, post the complete code you have written so far, completely explain what it’s supposed to do, and then completely explain what it actually does and how that’s different than what you want.

If the latter, get out your checkbook.

What is the linear potentiometer supposed to do?

What does "distance reached" mean to you and how will you measure it?

An useful start might be to say what you're set on using the linear pot FOR.

Then you might say what distance it is that you need to travel with extreme accuracy (and what extreme accuracy means to you...I tend to think in terms of better than micron accuracies but that may not be what you mean).

Or you could just tell us what the project actually is. Then show us the code that as decent Arduino coder you have produced for it so far and say what problems you're having with it.


When you say "linear potentiometer", do you mean a rotary pot with linear resistance taper or a "slide" pot?