Why does my variable count, Counts up automatically

the front right sensor are used for line tracking

i got no idea why does my count count up by itself automatically when the condition is not trigger

int count;

//----FRONT RIGHT SENSOR---- //
int FrontRight_Left = 40;
int FrontRight_Mid = 41;
int FrontRight_Right = 42;

int FrontRight_Left_sensorvalue;
int FrontRight_Mid_sensorvalue;
int FrontRight_Right_sensorvalue;

//----FRONT Left SENSOR---- //
int FrontLeft_Left = 44;
int FrontLeft_Mid = 45;
int FrontLeft_Right = 46;

int FrontLeft_Left_sensorvalue;
int FrontLeft_Mid_sensorvalue;
int FrontLeft_Right_sensorvalue;

//--BACK Right Sensor--//
int BackRight_Left = 48;
int BackRight_Right = 49;

int BackRight_Left_sensorvalue;
int BackRight_Right_sensorvalue;

//--BACK Left Sensor--//

int BackLeft_Left = 50;
int BackLeft_Right = 51;

int BackLeft_Left_sensorvalue;
int BackLeft_Right_sensorvalue;



///--------MOTOR--------///

//---Motor A //
int ENA = 2;
int IN1 = 22;
int IN2 = 23;

//--- MotorB //
int ENB = 3;
int IN3 = 24;
int IN4 = 25;



void setup() {
  
Serial.begin(9600);

pinMode(FrontRight_Left, INPUT);
pinMode(FrontRight_Mid, INPUT);
pinMode(FrontRight_Right, INPUT);

pinMode(FrontLeft_Left, INPUT);
pinMode(FrontLeft_Mid, INPUT);
pinMode(FrontLeft_Right, INPUT);

 
pinMode(BackRight_Left, INPUT);
pinMode(BackRight_Right, INPUT);

pinMode(BackLeft_Left, INPUT);
pinMode(BackLeft_Right, INPUT);

pinMode (ENA, OUTPUT);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT); 

pinMode (ENB, OUTPUT);
pinMode (IN3, OUTPUT);
pinMode (IN4, OUTPUT); 

  
analogWrite(ENA,0);
analogWrite(ENB,0);

count=0;
}
  
  
void loop() {

  if(count==0)
  {
LineSensorReading();

if(FrontRight_Mid_sensorvalue==0&&BackLeft_Left_sensorvalue==1)
{
  Forward();

}
else if(FrontRight_Left_sensorvalue==0&&BackLeft_Left_sensorvalue==1)
{
  TurnLeft();   
}

else if(FrontRight_Right_sensorvalue==0&&BackLeft_Left_sensorvalue==1)
{
  TurnRight();
}

else if(FrontRight_Mid_sensorvalue==0&&BackLeft_Left_sensorvalue==0)
{
count++;
Serial.print(count);
  

}
else if(FrontRight_Left_sensorvalue==0&&BackLeft_Left_sensorvalue==0)
{
count++;
Serial.print(count);
}
else if(FrontRight_Right_sensorvalue==0&&BackLeft_Left_sensorvalue==0)
{
count++;
Serial.print(count);
}

}
if(count==1)
{
  MotorStop();
}

}
  
void LineSensorReading()
{
  
FrontRight_Left_sensorvalue=digitalRead(FrontRight_Left);
FrontRight_Mid_sensorvalue=digitalRead(FrontRight_Mid);
FrontRight_Right_sensorvalue=digitalRead(FrontRight_Right);

FrontLeft_Left_sensorvalue=digitalRead(FrontLeft_Left);
FrontLeft_Mid_sensorvalue=digitalRead(FrontLeft_Mid);
FrontLeft_Right_sensorvalue=digitalRead(FrontLeft_Right);

BackRight_Left_sensorvalue=digitalRead(BackRight_Left);
BackRight_Right_sensorvalue=digitalRead(BackRight_Right);

BackLeft_Left_sensorvalue=digitalRead(BackLeft_Left);
BackLeft_Right_sensorvalue=digitalRead(BackLeft_Right);
}

void DisplayReading()
{
Serial.print("FrontRight_Left_sensorvalue  ");
Serial.print(FrontRight_Left_sensorvalue);
Serial.print("   ");
Serial.print("FrontRight_Mid_sensorvalue  ");
Serial.print(FrontRight_Mid_sensorvalue);
Serial.print("   ");
Serial.print("FrontRight_Right_sensorvalue  ");
Serial.print(FrontRight_Right_sensorvalue);
Serial.println("");


Serial.print("FrontLeft_Left_sensorvalue  ");
Serial.print(FrontLeft_Left_sensorvalue);
Serial.print("   ");
Serial.print("FrontLeft_Mid_sensorvalue  ");
Serial.print(FrontLeft_Mid_sensorvalue);
Serial.print("   ");
Serial.print("FrontLeft_Right_sensorvalue  ");
Serial.print(FrontLeft_Right_sensorvalue);
Serial.println("");

Serial.print("BackRight_Left_sensorvalue  ");
Serial.print(BackRight_Left_sensorvalue);
Serial.print("   ");
Serial.print("BackRight_Right_sensorvalue  ");
Serial.print(BackRight_Right_sensorvalue);
Serial.println("");
 
Serial.print("BackLeft_Left_sensorvalue  ");
Serial.print(BackLeft_Left_sensorvalue);
Serial.print("   ");
Serial.print("BackLeft_Right_sensorvalue  ");
Serial.print(BackLeft_Right_sensorvalue);
Serial.println(""); 
Serial.print(count);
Serial.println("");
Serial.println("");
Serial.println(""); 
Serial.println("");
Serial.println("");
}

void Reverse()
{
  
analogWrite(ENA,150);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
analogWrite(ENB,150);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);  
  
}

void Forward()
{

  
  
analogWrite(ENA,125);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);

analogWrite(ENB,120);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);


}

void TurnLeftSlight()
{
  
analogWrite(ENA,100);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);

analogWrite(ENB,100);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);  
  
}

void TurnRightSlight()

{
  
analogWrite(ENA,100);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);

analogWrite(ENB,100);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);  

}


void TurnLeft()

{
 
analogWrite(ENA,110);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
analogWrite(ENB,130);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);  

}

void TurnRight()

{
  
analogWrite(ENA,130);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);

analogWrite(ENB,100);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);  

}



void MotorStop()
{
analogWrite(ENA,0);
 
analogWrite(ENB,0);

  
}

void TurnLeft90deg()

{
  analogWrite(ENA,0);
digitalWrite(IN1,HIGH);
[b][i][img]digitalWrite[/img][/i][/b](IN2,LOW);
analogWrite(ENB,150);
digitalWrite(IN3,LOW);
digitaquotete(IN4,HIGH);  
}

You have count++ in 3 places if I saw correctly... one of those ifs must be triggered and doing the count++.

Maybe change you Serial.prints to identify which count++ is being triggered?

but when i change count++; to a function MotorStop(); it worked exactly fine the robot move along the line till trigger stop

if i use count++; it did not even reach the trigger and it just counts up and stop

Which of the three count++ lines is activated though?

when i remove the other 2 count++ and tried again it was active again . it counts up by itself

if(FrontRight_Mid_sensorvalue==0&&BackLeft_Left_sensorvalue==1)
{
  Forward();

}
else if(FrontRight_Left_sensorvalue==0&&BackLeft_Left_sensorvalue==1)
{
  TurnLeft();   
}

else if(FrontRight_Right_sensorvalue==0&&BackLeft_Left_sensorvalue==1)
{
  TurnRight();
}

else if(FrontRight_Mid_sensorvalue==0&&BackLeft_Left_sensorvalue==0)
{
count++;
Serial.print(count);
}


}
if(count==1)
{
  MotorStop();
}

so make your serial.print also print the sensor values.... they must be 0...

else if(FrontRight_Mid_sensorvalue==0&&BackLeft_Left_sensorvalue==0)
{
Serial.println("Hello"); // to check we're in the correct "if"
Serial.println(FrontRight_Mid_sensorvalue);
Serial.println(BackLeft_Left_sensorvalue);
Serial.println(count);  //before
count++;
Serial.print(count); //after
}
if(FrontRight_Mid_sensorvalue==0&&BackLeft_Left_sensorvalue==1)

Isyourspacekeybroken?

[b][i][img]digitalWrite[/img][/i][/b](IN2,LOW);

I really don't think that will even compile.

Tools + Auto Format was not added to the menu just for amusement. Learn what it does before you post code again.

What kind of sensors are you reading? What does your serial data look like?

Serial.print(count);

Anonymous output sucks.

sorry i will correct my posting and coding, i found out my problem whenever i program it and read the first reading of all my QRD1114 sensor will be 0 , when it suppose to be high , and than the 2nd reading it will be all normal