# Control/count rotations of a DC motor

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?

• Other than with a rotary encoder? Apr 23 '14 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)? Apr 23 '14 at 14:10
• With gears, a belt, or a chain. Apr 23 '14 at 14:10
• 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 Apr 23 '14 at 15:26
• Thanks for the advice. Would a question like this be more suited to robotics.stackexchange.com? Apr 23 '14 at 16:26