A collection of tutorials that show you how to control DC motors using an Arduino Micro Controller.
How the motors are controlled is hardware dependent.
Understanding How to Control DC Motors in Projects – Detailed and simple
Controlling DC Motor Speed and Direction with push-buttons – A follow on to the tutorial above.
IR Controlled DC Motor using Arduino– https://circuitdigest.com/microcontroller-projects/ir-controlled-dc-motor-using-arduino – Shows how to control a motor with a relay and IR detector.
The code to do this is just below.
) Rotate DC motor forward and reverse at set speed (withspeed control)
/*this program will rotate DC motor forward for 5 sec
at 40%speed then stop for 2 sec and again rotate motor reverse for
5 sec at 80% speed continuously
DC_Motor motor2(9, 10, 1);