Arduino Programmer needed (DC motor to servo) will pay

Hi guys,

I need someone to modify my code such that my dc motor works as servo. I am using arduino mega with this motor and this motor controller.

I want it to work as servo motor does. Give it a position and motor moves to that position.

For example If I give my Input/setpoint as 50, motor shaft should move that many counts. And then if I give my Input as 0, it should move back position zero. I have tried it but could not get it done.

You don't have to worry about tuning, I will tune it myself.

Message me and we can discuss.

Hi DC1991,

Can you describe what you’ve tried so far or post a copy of the code?

It almost sounds like you’re describing a stepper motor.

There are some motor experts out here that may have already done this.


Hi Patduino,

I have posted it here in programming question :

I am not a programmer. And have been stuck here for quite some time.

Ok this seems not too difficult. The motor comes with a pair of quadrature sensors that give 7 pulses per revolution (an odd number, but whatever) giving you an accuracy of at best 12.8 degrees.

The motor controller - Jeez, that’s a lot of pins. Do you already have code that makes it go? If it’s just a matter of counting quadrature pulses and you can supply a set of forward/reverse/stop functions that other code can call, then that’s reasonably straightforward. If you need code to actually talk to the board so it understands, that might be a bit more involved. Did you need some sort of soft start/stop?

In any case, quadrature code is not difficult. First, debounce your inputs. You’ll have an A and a B that will do this.

A -

  • B

Note that when there’s a change, either A changes or B changes. If A changes, then if the new value of A==B, increment the counter, otherwise decrement it. If B changes, then if the new value of B==A, decrement the counter, otherwise increment it.

Once you have worked out which way around forward and reverse are, then in your loop you put the motor in forward (or reverse) and wait for the counter to be >= (or <=) your target.

It might be easier to post the code you want modified.