What Is the L298N Motor Driver?
The L298N is a high-power dual H-bridge motor driver that allows you to control the direction and speed of two DC motors or a stepper motor. It supports high current loads and is perfect for robotics and automation projects.
Key Features
- Dual H-bridge configuration for independent motor control
- Supports motors up to 2A per channel
- Compatible with 5V to 35V power supplies
- Built-in 5V regulator
Connecting the L298N
Follow these steps to connect the L298N to your microcontroller:
- Connect VCC to your motor power supply (5V–35V).
- Attach GND to the ground of both the motor and the microcontroller.
- Connect IN1–IN4 to digital pins on your microcontroller for motor control.
- Use the EN A and EN B pins to enable/disable motor channels.
- Connect your DC motors to the OUT1/OUT2 and OUT3/OUT4 terminals.
Arduino Example Code
#define ENA 9
#define IN1 8
#define IN2 7
void setup() {
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
}
void loop() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 128); // Set speed
delay(2000);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA, 128); // Reverse direction
delay(2000);
}