Back to: Robotics & Artificial Intelligence (Class IX)
In this module, you will learn how to interface a DC motor with Arduino using the L298 motor driver. The focus will be on controlling the direction of the motor (clockwise and counterclockwise) using two control pins. This project will help you understand how to manipulate motor direction through digital signals.
Components Required:
- 1 x Arduino Uno
- 1 x L298 Motor Driver
- 1 x DC Motor
- Jumper wires
- Breadboard
- Power supply (9V recommended for the motor)
- USB Cable (to connect Arduino to PC)
Circuit Diagram:
- L298 Motor Driver Pins:
- IN1 and IN2: These pins control the direction of the motor.
- OUT1 and OUT2: These pins are connected to the motor.
- Enable Pin (ENA): This pin enables or disables the motor. Since we are not controlling speed, we can connect this to a high logic (5V).
- VCC: Connect to the motor’s power supply (e.g., 12V).
- GND: Connect to the ground.
- Arduino Pins:
- IN1 and IN2 of the L298 driver will be connected to two digital pins on the Arduino (e.g., pins 8 and 9).
- OUT1 and OUT2 of the L298 driver will be connected to the terminals of the DC motor.
Step-by-Step Guide:
Step 1: Wiring the Circuit
- Motor Connection: Connect the DC motor terminals to OUT1 and OUT2 on the L298 motor driver.
- Motor Power Supply: Connect the motor’s external power supply (e.g., 12V) to the VCC pin of the L298 driver and ground (GND) to the common ground of Arduino.
- Enable Pin: Connect the ENA pin of the motor driver to 5V to enable the motor.
- Direction Control: Connect IN1 of the motor driver to digital pin 8 and IN2 to digital pin 9 of the Arduino.
- Ground Connection: Ensure the ground (GND) of the Arduino and the motor power supply are connected to the motor driver’s ground.
Writing the Arduino Code
int IN1=8;
int IN2=9;
void setup()
{
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
}
void loop()
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
delay(1000);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
delay(1000);
}