6.5 DC Motors
6.5.1 Introduction
A DC motor is an actuator that converts electrical energy into rotational mechanical energy.
It is commonly used where continuous rotation is required.
6.5.2 Types
Examples include:
- Brushed DC motor
- Gear motor
- High-speed DC motor
- Coreless DC motor
6.5.3 Working Principle
When current flows through the motor windings, a magnetic field is produced. Interaction between magnetic fields produces rotational motion.
The direction of rotation can be changed by changing the polarity of the motor supply.
6.5.4 DC Motor Driver
An Arduino pin should not normally be used to power a DC motor directly.
A motor driver or suitable transistor/MOSFET circuit should be used.
Common motor drivers include:
- L298N
- L293D
- TB6612FNG
A motor driver allows the Arduino to control:
- Motor direction
- Motor speed
- Motor start/stop
6.5.5 Connecting a DC Motor to Arduino
Example using a motor driver:
|
Driver |
Arduino |
|
IN1 |
D7 |
|
IN2 |
D8 |
|
ENA/PWM |
D9 |
|
GND |
GND |
|
Motor output |
DC Motor |
|
Motor supply |
External supply |
6.5.6 Speed Control Using PWM
PWM can be used to control motor speed.
Arduino Uno PWM values normally range from:
0 to 255
- 0 = motor stopped
- 255 = maximum commanded PWM duty cycle
6.5.7 Direction Control
Example:
IN1 = HIGH
IN2 = LOW
→ Forward
IN1 = LOW
IN2 = HIGH
→ Reverse
IN1 = LOW
IN2 = LOW
→ Stop
The exact behavior depends on the motor driver.
6.5.8 Arduino Programming and Code
int IN1 = 7;
int IN2 = 8;
int ENA = 9;
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
}
void loop() {
// Forward
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 200);
delay(3000);
// Stop
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0);
delay(1000);
// Reverse
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA, 150);
delay(3000);
// Stop
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
analogWrite(ENA, 0);
delay(1000);
}
6.5.9 Code Description
IN1 and IN2 control the direction of the motor.
ENA controls motor speed using PWM.
digitalWrite() determines the direction.
analogWrite() controls the PWM duty cycle.
6.5.10 Applications
DC motors are used in:
- Robots
- Conveyor systems
- Fans
- Pumps
- Automated machines
- Toy vehicles
- Electric vehicles
- Industrial equipment


