Using an Arduino and an L293D IC, can I control the number of rotations a DC motor makes? Or can I only control the direction and speed of the motor?

I purchased a two-wheeled robot platform to learn Arduino programming and electronics. The platform is here: http://www.robotshop.com/en/dfrobot-2wd-mobile-platform-arduino.html

Each wheel is controlled by a DC motor. I followed Adafruit's tutorial (https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing) to control the motors with the help of an L293D IC.

Now I realize that I can't directly control the rotations of the motor. I can control the direction, voltage, and time of the rotation. For example: turn forward at 50% voltage for 500 milliseconds.

But that's difficult to translate into actual rotations. The speed of the motor varies according to voltage (like if I switch from 2AA batteries to 4AA's) and weight (adding sensors slows the motors down). Every time I change voltage or weight, I have to guess how much voltage/time causes a single rotation.

I think I should just buy stepper motors. Before I do that, I'll ask the community: Is there a way to control DC motors by rotations rather than time?

  • 2
    Other than with a rotary encoder? Commented Apr 23, 2014 at 14:06
  • I don't understand how to connect a rotary encoder to a DC motor. I see rotary encoder has a knob on it, and the three pins tell the Arduino how many degrees the knob has turned. But how would you tie that knob to the DC motor (or the wheel the motor turns)? Commented Apr 23, 2014 at 14:10
  • With gears, a belt, or a chain. Commented Apr 23, 2014 at 14:10
  • 1
    Or a shaft coupler, though that can require more precise alignment. Steppers motors are generally not used for mobile robots as they are fairly heavy and power hungry for their power. Depending on your resolution needs, you can also make your own optical or magnetic encoders, especially if you can work near the rim of a wheel. A quadrature system will give you 4 times the element resolution, so if you have a working diameter that can support 8 or 16 physical elements with two spaced sensors you can get a decent resolution (32 or 64 counts/revolution) for motion. See robotics.stackechange.com Commented Apr 23, 2014 at 15:26
  • Thanks for the advice. Would a question like this be more suited to robotics.stackexchange.com? Commented Apr 23, 2014 at 16:26

2 Answers 2


As you've discovered, there are a lot of variables involved, so you need some sort of feedback. A popular way to do this is with an encoder, but depending on your needs, other kinds of sensors can make do. For example, if your problem is keeping the robot going in a straight line, an electronic compass can help. For a line following robot, the line sensors are usually enough. Range sensors can track your distance. You get the idea.


Stepper would be heavy and battery consuming, as Ignacio says.

Pololu makes an encoder for a wheel: http://www.pololu.com/product/1217, but obviously you can implement this in other ways too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.