The DC motors we will be using are called brushed DC motors. The shaft must rotate freely inside of the commutator, so we cannot have permanent connections. Therefore, the electricity is transferred from the source to the rotor using brushes which allow the shaft to rotate freely but still maintain points of contact for electricity to flow. Thus, the name "brushed" DC motor.
As the shaft spins, the commutator energizes different rotor coils. The electricity flowing through these coils creates a magnetic field that interacts with the magnetic field of the magnets permanently mounted inside of the stator. As the motor spins, the polarity of the magnetic fields in the rotor coils changes. It repels away from one magnet and attracts towards another magnet. As it reaches the other magnet, polarity changes and it repeats this process indefinitely.
These are rue DC motors. Once you start applying a DC voltage, they spin continuously at a fixed rate. To control the speed, pulse motor on/off quickly using PWM (with analogWrite() function). Can't drive these motors directly from the Arduino pins as they don't provide enough current. Use an external power supply and transistors or an H-bridge circuit to drive the motor.
The L293D is a dual H-bridge motor driver. An H-bridge is a type of circuit used to drive a motor both forward and reverse by switching polarity. It is a dual H-bridge because it can drive up to two motors. It is comprised of a series of transistors to allow for easy pulsing of the motor and changes in direction. It is built for higher current applications to withstand the power required by motors. It is called a H-bridge due to its semblance with the letter H in its circuit representation.
For unidirectional (forward only) motor control, see this Adafruit Tutorial: https://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors
For bidirectional (forward & reverse) motor control, see this Adafruit Tutorial: https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing
For bidirectional control of two motors with a L293D dual h-bridge circuit (like in a two-wheeled robot application), use the pinout described below. You can use any digital pins; the code I provide uses the pin numbers described below.
For unidirectional (forward only) motor control, see this Adafruit Tutorial: https://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors
For bidirectional (forward & reverse) motor control, see this Adafruit Tutorial: https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing
For bidirectional control of two motors with a L293D dual h-bridge circuit (like in a two-wheeled robot application), use the code below. Motor functions are described and defined within the motors.ino file.
https://create.arduino.cc/editor/mjdargen_ncsu/53622f11-7329-4498-a161-c21350163d49/preview