Introduces transistor to control external power supply for motor. Also warns about current produced by motor when it keeps spinning after removing power supply. This generated current can damage main power source. Diode is used to short circuite this back-voltage.

Arduino Wiring