You are on page 1of 4

NARVASA, YSAVELLE Objectives:

SBECE-1A • The L293D IC can control the speed


and direction of two DC motors.
Activity: Controlling DC Motors with L293D
• This IC has 16 pins and is used to
Motor Driver IC and Arduino.
operate a pair of DC motors in any
Description: direction instantly. It means that we
can control two DC motors using an
A l293D motor driver IC is used by Arduino
L293D IC. This IC can also run small
to operate a DC motor. The L293d circuit
and silent large motors.
diagram is used to regulate the speed and
direction of a direct current motor. The l293d Coding:
motor driver IC is a 16-pin motor driver IC
// Motor A connections
that can operate two DC motors in any
direction at the same time. That means it can int enA = 8;
operate up to two DC motors independently,
making it perfect for developing a two-wheel int in1 = 5;
robot car. The l293d is intended to deliver int in2 = 6;
bidirectional driving currents of up to 600
mA (per channel) at voltages ranging from // Motor B connections
4.5 V to 36 V. (at pin 8). There are two +V int enB = 7;
pins on the L293D. (8 and 16). The power for
the motors is provided by pin '+Vmotor (8), int in3 = 10;
while the chip's logic is provided by pin +V int in4 = 9;
(16).
void setup() {
Components and Supplies:
// Set all the motor control pins to outputs
1 × Arduino Uno
pinMode(enA, OUTPUT);
1 × DC Motors
pinMode(enB, OUTPUT);
1 × 220Ω Resistor
pinMode(in1, OUTPUT);
22 × Jumper wires
pinMode(in2, OUTPUT);
1 × Ultrasonic Sensor
pinMode(in3, OUTPUT);
1 × Breadboard
pinMode(in4, OUTPUT);
1 × 9v Battery
// Turn off motors - Initial state
2 × LEDs
digitalWrite(in1, LOW);
1 × L293D IC
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
} delay(2000);

void loop() { // Turn off motors


directionControl(); digitalWrite(in1, LOW);
delay(1000); digitalWrite(in2, LOW);
speedControl(); digitalWrite(in3, LOW);
delay(1000); digitalWrite(in4, LOW);
} delay(2000);
}
// This function lets you control spinning // This function lets you control speed of
direction of motors the motors
void directionControl() { void speedControl() {
// Set motors to maximum speed // Turn on motors
// For PWM maximum possible values digitalWrite(in1, LOW);
are 0 to 255
digitalWrite(in2, HIGH);
analogWrite(enA, 255);
digitalWrite(in3, LOW);
analogWrite(enB, 255);
digitalWrite(in4, HIGH);
// Turn on motor A & B
// Accelerate from zero to maximum
digitalWrite(in1, HIGH); speed
digitalWrite(in2, LOW); for (int i = 0; i< 255; i++) {
digitalWrite(in3, HIGH); analogWrite(enA, i);
digitalWrite(in4, LOW); analogWrite(enB, i);
delay(2000); delay(20);
}
// Now change motor directions
digitalWrite(in1, LOW); // Decelerate from maximum speed to
zero
digitalWrite(in2, HIGH);
for (int i = 255; i>= 0; --i) {
digitalWrite(in3, LOW);
analogWrite(enA, i);
digitalWrite(in4, HIGH);
analogWrite(enB, i);
delay (20);
START
}
//Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW); INITIALIZATION
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay (2000); L293D MOTOR
DRIVER
}
ANALYZING

Analyzation:
• When the jumper wire is not
properly inserted, it will not work. YELLOW LED ON
• If there is an error in the code you (FORWARD)
enter into the Arduino, it will not
DELAY (2000)
operate.
• The L293D IC can control the
speed and direction of two DC
motors.
YELLOW LED OFF
Conclusion:
(STOP)
• I learned how to control DC motors
with the L293D, which can attach to
make the DC motors run in a
specified direction depend on the
code. RED LED ON
• Capable of spinning clockwise or (BACKWARD)
counterclockwise. The spin direction
DELAY (2000)
is determined by the polarity of the
motor and how it is connected to the
power source.

RED LED OFF


(STOP)
Schematic Diagram:

M M

You might also like