Index

Introduction
A DC motor (Direct Current motor) is an electrical machine that converts direct current (DC) electrical energy into mechanical rotational motion. It is one of the simplest and most commonly used types of electric motors. The working of a DC motor is based on Faraday’s Law of Electromagnetic Induction. When current flows through the motor’s coil placed in a magnetic field, a force is generated that causes the motor shaft to rotate.
Required Components
- Arduino UNO
- Power Supply Module
- Motor
- L293D IC
- Jumper Wire
- Breadboard
Pinout
L293D is an IC chip (Integrated Circuit Chip) with a 4-channel motor drive. You can drive a unidirectional DC
motor with 4 ports or a bi-directional DC motor with 2 ports or a stepper motor.

Port description of L293D module is as follows:
Pin name | Pin number | Description |
In x | 2, 7, 10, 15 | Channel x digital signal input pin |
Out x | 3, 6, 11, 14 | Channel x output pin, input high or low level according to In x pin, get connected to +Vmotor or 0V |
Enable1 | 1 | Channel 1 and channel 2 enable pin, high level enable |
Enable2 | 9 | Channel 3 and channel 4 enable pin, high level enable |
0V | 4, 5, 12, 13 | Power cathode (GND) |
+V | 16 | Positive electrode (VCC) of power supply, supply voltage 4.5~36V |
+Vmotor | 8 | Positive electrode of load power supply, provide power supply for the Out pin x, the supply voltage is +V~36V |
When using L293D to drive DC motor, there are usually two kinds of connection.
The following connection option uses one channel of the L239D, which can control motor speed through
the PWM, However the motor then can only rotate in one direction.

The following connection uses two channels of the L239D: one channel outputs the PWM wave, and the
other channel connects to GND. Therefore, you can control the speed of the motor. When these two
channel signals are exchanged, not only controls the speed of motor, but also can control the speed of the motor.

In practical use the motor is usually connected to channel 1 and by outputting different levels to in1 and in2
to control the rotational direction of the motor, and output to the PWM wave to Enable1 port to control the
motor’s rotational speed. If the motor is connected to channel 3 and 4 by outputting different levels to in3
and in4 to control the motor’s rotation direction, and output to the PWM wave to Enable2 pin to control the
motor’s rotational speed.
Circuit Diagram / Wiring
- L293D 1 (Enable 1) → Arduino 9
- L293D 2 (Input 1) → Arduino 2
- L293D 3 (Output 1) → Motor terminal 1
- L293D 6 (Output 2) → Motor terminal 2
- L293D 7 (Input 2) → Arduino 3
- L293D 8 (Vcc2) → Motor power (e.g. 9V)
- L293D 16 (Vcc1) → 5V from Arduino
- L293D 5 (GND) → GND

Arduino Code / Programming
int motorPin1 = 2;
int motorPin2 = 3;
int enablePin = 9;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
}
void loop() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin, 200); // Speed (0-255)
delay(3000);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(3000);
}
Explanation
motorPin1
andmotorPin2
control direction through logic levels.enablePin
controls motor speed usinganalogWrite
.- The loop changes direction every 3 seconds.
Troubleshooting
- If the motor doesn’t run, check the power source on L293D pin 8.
- Swap motor wires if it spins in the wrong direction.
- Ensure GND of Arduino and motor power supply are connected together.