# How do I measure speed and manipulate the speed based on distance covered?

I'm doing a project on arduino. I'm using a online simulator to design the circuit. I have a dc motor. How do we measure the rpm,speed at that rpm,distance covered by the motor in a given time. For example,

When motor starts, it starts rotating slowly and gradually increases it's RPM. When it covered a distance of 50 meters, the motor slows down and stops. After 10 seconds, the motor starts again at that 50 meter point and goes to 100 meters point and stops. Like this it stops for every 50m. For this we need to keep track of the distance travelled by motor and control it's speed.

How do I achieve the above working. I have tried alot and verified many tutorials but couldn't understand what to do. Please help me out. (The online simulator I'm using has a L293D motor driver, IR sensor and a ultrasonic distance sensor in it's component list.)

• Put an encoder on the shaft; this way you will be able to "read" the rotational speed. Whis is linked to the vehicle by a constant. And integrating the speed (summing up) will give you the distance travelled. Jun 14, 2017 at 9:27
• Rather than computing and integrating the speed (which amount to computing the integral of a derivative), you just have to count the pulses from the encoder. Jun 14, 2017 at 9:44
• @EdgarBonet yes, in fact summing up the "frequencies" that you read is equivalent to counting the pulses... I tend to overcomplicate things ;) Jun 14, 2017 at 11:52