Turning on and off DC motors with code

I'm working on an engineering project where I need to run and turn off multiple motors with Arduino. My question is how I can turn a DC motor on and off with code?



Are the motor only running in one direction or must the be able to run forward and reverse. If only one direction you can use a transistor (MOSFET) to control it and the command would be digitalWrite(pin, HIGH) for a N channel MOSFET with the gate to pin. For forward and reverse control you need an H-bridge. The specific command(s) would depend on the H-bridge selected.