MOTOR DRIVER INTERFACING WITH ARDUINO
A motor driver is an electronic component that uses the principle of H-bridge to control the output voltage and the direction of rotation of the motor. An L298N (motor driver) consists of four output pins, four input pins, three power pins and two pairs of enabling pins as shown in the below figure.
L298N pinout
The board has a premounted 5V regulator to maintain a constant output voltage of 5V at every output pin. A motor driver is a type of input amplifier. It amplifies the signal that comes from the Arduino and provides at the output because the only microcontroller cannot deliver a full output voltage to run the motor at rated speed. The power pins are used to powerup the motor driver with an external power source and input pins get information from a microcontroller, in our case that is Arduino, to control the direction of motors.
The same configuration applies for L293D also, but the difference comes in them with the pair of enabling pins and power withstanding capacity of L298N.
INTERFACING L298N with ARDUINO:-
The Arduino interfacing with the L298N is given below.
- The 12V pin is connected to the positive of the battery.
- 5V pin of the motor driver is connected to 5V of Arduino.
- The ground pin of the motor driver is connected to the battery negative and one of the ground pin of Arduino.
- The four input pins are connected to the digital pins of Arduino as shown in the figure.
- The four output pins of the motor driver are connected to the terminals of the motor.
- See that connections are made properly and be careful with the terminals of the battery.
- See that the ground pin and 12V pin do not touch each other as it will lead to the failure of the battery and L298N module.
WORKING EXPLANATION OF L298N
Generally, a motor works when there is a potential difference between two of its terminals. This potential difference is created and controlled by the Arduino (microcontroller unit). We know that we can program output voltages in Arduino.
Using two digital pins with one as HIGH and one as LOW we are creating a potential difference between the terminals of the motor. One pin of the motor will be in higher potential and others will be in lower potential. If the voltage at terminals is interchanged means HIGH in above is made LOW and LOW is made HIGH then the direction of the motors is reversed. If both the terminals are given as either LOW or HIGH then we can see that there is no potential difference between the terminals therefore the motors won’t run. In this way, we can control the direction of rotation of motors.
Arduino program of L298N
void setup() {
//pin declarations
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
}
void loop(){
// both the motors rotate in clockwise directions
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
delay(5000);
//both the motors rotate in anticlockwise direction
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
delay(5000);
// one motor rotate in clockwise direction and another motor rotate in anticlockwise direction
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
delay(5000);
//both the motors don’t rotate as the potentials are maintained same at both the terminals of motor
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
delay(5000);
}
CONCLUSION
Hence here about interfacing of Arduino with motor driver and its working, operations are discussed
Also read about Arduino