What does the motor speed mean?


#1

When I type motor1.run(255); the motor moves at speed 255. This is just a number. Does it translate to something like cm/minute or something like that?


#2

That number translates to how much power is sent to the motor, from 0 (0%) to 255 (100%). How fast the motor turns as a result will depend on the motor itself, and how much resistance there is on it. A motor with nothing resisting it will spin faster than one with a load applied. The simplest way to think of it is that you’re changing the amount of force being output from the motor, not the speed of it. If the force applied isn’t enough to overcome inertia, friction, etc, then the motor still won’t move.


#3

The number determines the duty cycle of the PWM signal used to control the speed of the motor, see https://www.arduino.cc/en/Reference/AnalogWrite and https://en.wikipedia.org/wiki/Pulse-width_modulation.


#4

The Arduino controller can only send a digital signal, so it either sends “on” (5 V) or “off” (0 V). To emulate analog (values between 0 and 5 V) it can pulse the signal on and off. The frequency with which it does this is called the duty cycle. As was mentioned, it is a percent, and 255 translates to 100%. So 50% power is actually 100% power 50% of the time.

The Arduino pulses are about 490 per second. If we round to 500 to make the math simple, the pulse lasts 2 milliseconds (ms). For a duty cycle of 50%, 1ms of the pulse would be “on” and the other ms would be “off”. For a duty cycle of 25%, 0.5 ms of the pulse would be “on” and 1.5 ms would be off.


#5