I am working on my first robot project. I can't think of any way to automatically and programmatically control the speed. for example I want the robot to start with a very low speed and gradually increase the speed, when an obstacle is detected, it should gradually decrease its speed.
I've got mine running under the control of a TV remote where I use the volume up and down keys to speed up and slow down- but the same principles would hold for doing it with a sensor or just program control at start up.
Use PWM from the Arduino outputs to pulse the motor to give its speed. I'm using a MotoMama board with a 298, where each motor enable pin (there are two, for two motors) can be PWM'd for speed.
The output on a PWM pin goes from 0 to 255. So just have some code that increases the analogWrite gradually as it pulls off, something like this, where I'm using pin5 as a PWM ~ pin....