The L298 is a robust dual H-bridge motor driver integrated circuit (IC) designed to control the speed and direction of two DC motors simultaneously. It is widely used in robotics, automation, and other electronic applications that require precise motor control. The L298 can handle high current loads and is suitable for driving medium to large motors, making it a popular choice for hobbyists and professionals alike.
Pin Number | Pin Name | Description |
---|---|---|
1 | Vs | Power supply for the motors (up to 46V) |
2 | GND | Ground |
3 | Vss | Logic supply voltage (5V from Arduino) |
4 | Out 1 | Output to motor A (one side of the H-bridge) |
5 | Out 2 | Output to motor A (other side of the H-bridge) |
6 | EnA | Enable input for motor A (PWM signal for speed control) |
7 | In1 | Input 1 for motor A (controls direction) |
8 | In2 | Input 2 for motor A (controls direction) |
... | ... | ... |
15 | In3 | Input 1 for motor B (controls direction) |
16 | In4 | Input 2 for motor B (controls direction) |
17 | EnB | Enable input for motor B (PWM signal for speed control) |
18 | Out 3 | Output to motor B (one side of the H-bridge) |
19 | Out 4 | Output to motor B (other side of the H-bridge) |
20 | Vs | Power supply for the motors (up to 46V) |
#include <Arduino.h>
// Define connections to the L298
const int enA = 9;
const int in1 = 8;
const int in2 = 7;
const int enB = 3;
const int in3 = 4;
const int in4 = 5;
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);
}
void loop() {
// Turn on motor A & B
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Set speed to 200 out of possible range 0-255
analogWrite(enA, 200);
analogWrite(enB, 200);
delay(2000); // Run motors for 2 seconds
// Now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000); // Run motors for 2 seconds
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(2000); // Wait for 2 seconds before next loop
}
Q: Can the L298 drive stepper motors? A: Yes, the L298 can be used to drive bipolar stepper motors with proper control signals.
Q: What is the maximum current the L298 can handle? A: The L298 can handle up to 2A per channel, but with proper heat sinking.
Q: Can I control the speed of the motors using the L298? A: Yes, by applying a PWM signal to the EnA and EnB pins, you can control the speed of the motors.