I am facing the same issue with my motor driver. Initially I ran the code and connected the L298N with Arduino and it worked fine. At that time motors were running absolutely fine. But when I ran it sometimes later then the motors are not running. However the motors are getting power but I think thy are getting very less power from the Motor Driver.
I directly ran motors from Arduino +5V pin and the motors were running fine. Is there something wrong with my L298N motor driver?
One more thing I checked the power for all the pins for L298N motor Driver and all pins are working fine.
Here is my complete program:
const int MOTOR_RIGHT = 1;
const int MOTOR_LEFT = 2;
const int MR_CONTROL_PIN_A = 8;
const int MR_CONTROL_PIN_B = 9;
const int ML_CONTROL_PIN_A = 10;
const int ML_CONTROL_PIN_B = 11;
void setup() {
// These two pins will act as output pin
pinMode(MR_CONTROL_PIN_A,OUTPUT);
pinMode(MR_CONTROL_PIN_B,OUTPUT);
pinMode(ML_CONTROL_PIN_A,OUTPUT);
pinMode(ML_CONTROL_PIN_B,OUTPUT);
Serial.begin(4800);
}
void loop()
{
// put your main code here, to run repeatedly:
forward(MOTOR_RIGHT);
forward(MOTOR_LEFT);
delay(5000);
stopMotor(MOTOR_RIGHT);
stopMotor(MOTOR_LEFT);
delay(1000);
backward(MOTOR_RIGHT);
backward(MOTOR_LEFT);
delay(5000);
stopMotor(MOTOR_RIGHT);
stopMotor(MOTOR_LEFT);
delay(1000);
}
/////////////////////////////////////////////////////////////////////
//Forward
void forward(int motorNo)
{
Serial.print("\r\n Forward : ");
Serial.print(motorNo);
switch(motorNo)
{
case MOTOR_RIGHT:
digitalWrite(MR_CONTROL_PIN_A,HIGH);
digitalWrite(MR_CONTROL_PIN_B,LOW);
break;
case MOTOR_LEFT:
digitalWrite(ML_CONTROL_PIN_A,HIGH);
digitalWrite(ML_CONTROL_PIN_B,LOW);
break;
default:
Serial.print("\r\n Error :Invalid Motor No ");
Serial.print(motorNo);
}
}
//////////////////////////////////////////////////////////////////////
void backward(int motorNo)
{
Serial.print("\r\n Backward : ");
Serial.print(motorNo);
switch(motorNo)
{
case MOTOR_RIGHT:
digitalWrite(MR_CONTROL_PIN_A,LOW);
digitalWrite(MR_CONTROL_PIN_B,HIGH);
break;
case MOTOR_LEFT:
digitalWrite(ML_CONTROL_PIN_A,LOW);
digitalWrite(ML_CONTROL_PIN_B,HIGH);
break;
default:
Serial.print("\r\n Error :Invalid Motor No : ");
Serial.print(motorNo);
}
}
///////////////////////////////////////////////////////////////////////
void stopMotor(int motorNo)
{
Serial.print("\r\n STOP : ");
Serial.print(motorNo);
switch(motorNo)
{
case MOTOR_RIGHT:
digitalWrite(MR_CONTROL_PIN_A,HIGH);
digitalWrite(MR_CONTROL_PIN_B,HIGH);
break;
case MOTOR_LEFT:
digitalWrite(ML_CONTROL_PIN_A,LOW);
digitalWrite(ML_CONTROL_PIN_B,LOW);
break;
default:
Serial.print("\r\n Error :Invalid Motor No : ");
Serial.print(motorNo);
}
}
Is there something wrong with my L298N ? How can I test it?