The Arduino can only provide 5V. This is far from what this motor needs to achieve its full speed. An external power source is used instead. The voltage provided to the motor can be controlled using the potentiometer.
void setup() {
pinMode(9, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0);
int outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(9, outputValue);
delay(100);
}
https://itp.nyu.edu/physcomp/labs/motors-and-transistors/using-a-transistor-to-control-high-current-loads-with-an-arduino/