arduino and l298 driver

Hi firends
i am using l298 driver
when i am sending 'f' from serial monitor all pins up are going high :frowning: and motor is not runing

please see my code below is anything wrong i done

thanks

int ENA=9; //Connect on Pin 9
int IN1=4; //Connect on Pin 4
int IN2=5; //Connect on  Pin 5
int ENB=10; //Connect on Pin 10
int IN3=6; //Connect on  Pin 6
int IN4=7; //Connect on  Pin 7

void setup() {
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  analogWrite(ENA,127);// Activate motor A
  analogWrite(ENB,127);// Activatemotor B
  Serial.begin(9600);

}
void loop(){


  // read the sensor:
  if (Serial.available() > 0) {
    char inByte = Serial.read();
    // do something different depending on the character received.  
    // The switch statement expects single number values for each case;
    // in this exmaple, though, you're using single quotes to tell
    // the controller to get the ASCII value for the character.  For 
    // example 'a' = 97, 'b' = 98, and so forth:

    switch (inByte) {

    case 'f':

      forward();
      Serial.write("forward"); 
      break;
    case 'r':    
      right();
      break;
    case 'l':
      left();
      break;
    case 's': 
      Stop();
      break;
    default:
      Serial.print("Invalid command");
    }

  }


}



void forward()
{

  digitalWrite(IN1,LOW); //clockwise
  digitalWrite(IN2,HIGH); 
  digitalWrite(IN3,LOW); //clockwise
  digitalWrite(IN4,HIGH);

}


void right()
{

  digitalWrite(IN1,HIGH); //Anti-clockwise
  digitalWrite(IN2,LOW);

  digitalWrite(IN3,LOW);  //clockwise
  digitalWrite(IN4,HIGH);

  digitalWrite(IN1,HIGH); //Anti-clockwise
  digitalWrite(IN2,LOW);

  digitalWrite(IN3,LOW);  //clockwise
  digitalWrite(IN4,HIGH);



}


void left()
{
  digitalWrite(IN3,LOW);  //clockwise
  digitalWrite(IN4,HIGH);
  digitalWrite(IN1,HIGH); //Anti-clockwise
  digitalWrite(IN2,LOW);


}


void Stop()
{

  digitalWrite(IN3,LOW);  //stop
  digitalWrite(IN4,LOW);
  digitalWrite(IN1,LOW);  //stop
  digitalWrite(IN2,LOW);

}

How do you know the pins are high?

edit: maybe the 1/2 speed PWM on the EN pins isn't enough to turn the motors.

yeah you are right JimboZA

when i run the motors without load they are working fine

really thanks :slight_smile:

Check your voltages: an L298 loses a minimum of 2V, and up to 5V (? not sure) under high current, so you may have very low voltage on the output side. You might need to put more V's in......

yeah i am using 12v battery

after changing to below code motors are running after load :smiley:

void setup() {
  pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  digitalWrite(ENA,HIGH);// Activate motor A
  digitalWrite(ENB,HIGH);// Activatemotor B
  Serial.begin(9600);

}

thanks :slight_smile: