DC motors can be used in several ways. Make sure you know your motor’s voltage and amp draw. You can plug power directly to your motor and it should just work. If however you want more nuanced control, you’ll need to use a technique called pulse width modulation or PWM. This technique instead of sending a steady voltage, creates pulses of voltage and so it is on and off at different times.
You can get a PWM signal with a DC motor controller driver, or you can control it via an Arduino, which allows you to design your own control technique.
If you do this, you will also need some external circuitry like an H-Bridge. There are several “driver boards” and “Motor Hats” that take care of this for you and you can choose the right one depending on your voltage (V) and current (A) needs.
For our examples here we will use a few of these:
If your motor is 5 to 25V and less than 2A, then we will use the L298N board, and follow this and/or this tutorial.