Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Project 28: Motor

Introduction

The L293D is a dual H-bridge motor driver IC used to control the speed and direction of DC motors.
It allows you to control 2 motors independently with external power supply support.
Arduino sends control signals to the L293D, which drives the motor accordingly.
This setup is widely used in robotic cars and basic automation projects.

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 (stepper motors are covered
later in this Tutorial)

Port description of L293D module is as follows:

Pin namePin numberDescription
In x2, 7, 10, 15Channel x digital signal input pin
Out x3, 6, 11, 14Channel x output pin, input high or low level according to In x pin, get
connected to +Vmotor or 0V
Enable11Channel 1 and channel 2 enable pin, high level enable
Enable29Channel 3 and channel 4 enable pin, high level enable
0V4, 5, 12, 13Power cathode (GND)
+V16Positive electrode (VCC) of power supply, supply voltage 4.5~36V
+Vmotor8Positive 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 and motorPin2 control direction through logic levels.
  • enablePin controls motor speed using analogWrite.
  • The loop changes direction every 3 seconds.

Testing & 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.

    Leave a Reply

    Your email address will not be published.

    Need Help?