Problem in code of Line Follower

Hey, Im trying to use this code in my Line Follower Robot, and for some reason its just does not work.
The Robot always attend to the right side and ignore the Black Line.

I have a couple things that going on in the code.

  1. 2 IR sensor to detect the black line A1,A0.
    2)1 IR sensor for distance A2
    3)2 DC motors - the yellow one`s.
    4)L298

the connections are like this if I`m looking at the robot in the front.
The right motor is connecting to OUT1/2 in the L298
The left motor is connecting to OUT3/4

The right sensor is connecting to A0, Left to A1, A2 is the distance sensor.

the problem that i got all the time is the robot attend to go to the right side for some reason, even if i change the connection of the #define of the motors.

the distance sensor is only to stop the robot, and even he does not work, but in the serial monitor all the numbers are good.

what I`m doing wrong?

#define left_motor_direction1 1// HIGH/LOW
#define left_motor_direction2 2// HIGH/LOW
#define left_motor_power 3// 0-255
#define right_motor_direction1 4 //HIGH/LOW
#define right_motor_direction2 7//HIGH/LOW
#define right_motor_power 5// 0-255
#define green_led 6// HIGH/LOW
#define blue_led 13//HIGH/LOW
#define left_sensor A1//0-255
#define right_sensor A0//0-255
#define distance_sensor A2//0-255

int vleft;
int vright;
int vdis;

int value = 400;

void setup()
{
  Serial.begin(9600); 
  pinMode(left_motor_direction1, OUTPUT);
  pinMode(left_motor_direction2, OUTPUT);
  pinMode(right_motor_direction1, OUTPUT);
  pinMode(right_motor_direction2, OUTPUT);
  pinMode(green_led, OUTPUT);
  pinMode(blue_led, OUTPUT);

}

  void loop()
  {
     vleft = analogRead(A1);
     vright = analogRead(A0);
     vdis = analogRead(A2);
     Serial.print("left sensor = ");
     Serial.print(vleft);
     Serial.println();
     Serial.print("right sensor = ");
     Serial.print(vright);
     Serial.println();
     Serial.print("distance sensor = ");
     Serial.print(vdis);
     Serial.println();
 
     delay(2000);

    if (vright < value && vleft< value)
    {
      digitalWrite(left_motor_direction1, HIGH);
      digitalWrite(left_motor_direction2, LOW);
      digitalWrite(right_motor_direction1, HIGH);
      digitalWrite(right_motor_direction2, LOW);
      analogWrite(left_motor_power, 100);
      analogWrite(right_motor_power, 100);
    }
    else if (vright > value && vleft < value)
    {
      digitalWrite(left_motor_direction1, HIGH);
      digitalWrite(left_motor_direction2, LOW);
      digitalWrite(right_motor_direction1, LOW);
      digitalWrite(right_motor_direction2, LOW);
      analogWrite(left_motor_power, 100);
      analogWrite(right_motor_power, 100);
    }
    else if (vleft > value && vright < value)
    {
      digitalWrite(left_motor_direction1, LOW);
      digitalWrite(left_motor_direction2, LOW);
      digitalWrite(right_motor_direction1, HIGH);
      digitalWrite(right_motor_direction2, LOW);
      analogWrite(left_motor_power, 100);
      analogWrite(right_motor_power, 100);
    }
    else if (vdis >600 )
    {
      
      analogWrite(left_motor_power, 0);
      analogWrite(right_motor_power, 0);
    }
    

  }

What do your debug prints tell you?
What happens when you put the robot up on blocks and test the sensors individually?

Maybe try freeing-up the serial tx line.#define left_motor_direction1 1

TheMemberFormerlyKnownAsAWOL: What do your debug prints tell you? What happens when you put the robot up on blocks and test the sensors individually?

Maybe try freeing-up the serial tx line.#define left_motor_direction1 1

Ok i think i figure out why he attend to the right side. for some reason the lest motor is ruining faster then the left, but its does not explain why' for example, he don`t stop when an obstacle is in front of him.

and i cant free this. This is all the ports that available to me only then 0 that i dont use him. i have more things in the robot that i didn`t put yet, so all the ports are attached, only 0 is free.

and i can`t free this.

Well, don’t use it for serial debug prints.

TheMemberFormerlyKnownAsAWOL: Well, don't use it for serial debug prints.

the code itself look`k ok right? i just need the robot for the start to move straight right and left and stop. But for some reason he ignore every command.

ruppna:
the code itself look`k ok right?

Apart from the dual use of pin 1?

TheMemberFormerlyKnownAsAWOL: Apart from the dual use of pin 1?

yes

But you’ve fixed that, right?
How does it perform now?
What does the code look like now?