L239D MOTOR DRIVE
What is an L239D motor drive?
L293D is a 16-pin motor driver IC consist of quadruple half H drivers. It can simultaneously control the direction and speed of two DC motors.
Where is it used?
- L293d could be used to control the two motors at the same time.
- It has the ability to control the speed by using the enable pin.
- The direction is also easy to change.
- Voltage supply range is higher than other IC. Voltage range between 4.5-36 volts can easily handle by the IC to the motor.
- The motor has a maximum continuous range of current close to 600mA but the maximum peak current range is 1.2A
- It has an automatic shutdown system on thermal condition.
- Its working range is from 0 – 70 degree which is much higher for any small-sized IC.
- It has an internal back emp protection for IC and the controlling device.
CODE
// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections
int enB = 3;
int in3 = 5;
int in4 = 4;
void setup() {
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Turn off motors – Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop() {
directionControl();
delay(500);
speedControl();
delay(200);
}
// This function lets you control spinning direction of motors
void directionControl() {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite(enA, 200);
analogWrite(enB, 255);
// Turn on motor A & B
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(500);
// Now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(500);
// Turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
// This function lets you control speed of the motors
void speedControl() {
// Turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Accelerate from zero to maximum speed
for (int i = 0; i < 256; i++) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Decelerate from maximum speed to zero
for (int i = 255; i >= 0; –i) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
VIDEO
You must be logged in to post a comment.