line following robot need help badly ,noob here :(

Good day to all of you guys..

i need help for my code here..

my objective here is when my robot sense 4 lines it will stop and will not anymore go to any direction, regarding all data read which is a blackline.

i really need help badly please :frowning:

#include<Servo.h>

Servo Lwheel;
Servo Rwheel;



int LMInput=A0;
int LInput=A1;
int MInput=A2;
int RInput=A3;
int RMInput=A4;

int LMValue = 0;
int LValue = 0;
int MValue = 0;
int RValue = 0;
int RMValue = 0;

int Blackline = 710;
int counter = 0;


void setup()
{
 pinMode(20, OUTPUT); //LED PINS
 pinMode(52, OUTPUT);
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT); 
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT); 
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);

 Serial.begin(9600);
 Rwheel.attach(13);
 Lwheel.attach(12);
}
void loop()
{
 LMValue = analogRead (LMInput);
 LValue= analogRead (LInput);
 MValue=analogRead (MInput);
 RValue= analogRead (RInput);
 RMValue= analogRead (RMInput);

if  
  ( LMValue>Blackline && LValue>Blackline && MValue>Blackline && RValue>Blackline && RMValue >Blackline || LMValue >Blackline && LValue>Blackline && counter <5 || RMValue > Blackline && RValue >Blackline)
    {
      Serial.println("CHECKING");
      counter = counter + 1; 
      delay(300);
      Serial.println("COUNTER + 1"); 
      Serial.println(counter); 
      
       digitalWrite(48,HIGH);
      delay(20);
      
    
      digitalWrite(48,LOW);
      delay(20);
      
     

      digitalWrite(48,HIGH);
       delay(20);
      
      digitalWrite(48,LOW);
      delay(20);
    
  
           
       
 if (LMValue>Blackline && LValue>Blackline && MValue>Blackline && RValue>Blackline && RMValue >Blackline && counter ==2 )
       {
         Serial.println("STOP"); 
          Serial.println(); 
       counter=counter;
         RightwheelStop();
         LeftwheelStop();
         delay(20);
       }
    }
 
else if 
  (LMValue < Blackline && MValue >Blackline && RMValue <Blackline && counter !=2|| LMValue < Blackline && LValue<Blackline && MValue>Blackline && RValue<Blackline &&RMValue<Blackline )
    {
     Serial.println("FORWARD");
     RightwheelForward();
      LeftwheelForward();
      delay(50); 
    }

else if
  ( RValue >Blackline && LValue < Blackline && LMValue < Blackline &&counter!=2 ||RMValue<Blackline && RValue>Blackline && MValue<Blackline && LValue<Blackline && LMValue<Blackline ) 
    {
     Serial.println("RIGHT");
    RightwheelslowBackward();
    LeftwheelslowForward();
     delay(50);
    }
else if
  ( RMValue >Blackline && MValue < Blackline && LValue < Blackline && LMValue < Blackline || RMValue>Blackline && RValue>Blackline && MValue<Blackline && LValue<Blackline&&LMValue<Blackline &&counter!=2)
    {
    Serial.println("SHARPRIGHT");
    RightwheelslowBackward();
    LeftwheelslowForward();
    delay(50);
    }

else if
  ( LValue >Blackline && RValue < Blackline && RMValue < Blackline || LMValue<Blackline && LValue>Blackline && MValue<Blackline && RValue<Blackline && RMValue<Blackline &&counter!=2) 
    {
    Serial.println("LEFT");
    RightwheelslowForward();
    LeftwheelslowBackward();
    delay(50);
    }

else if
 ( LMValue >Blackline && MValue < Blackline && RValue < Blackline &&  RMValue < Blackline &&counter!=2 || LMValue >Blackline && LValue > Blackline&& MValue < Blackline && RValue < Blackline &&  RMValue < Blackline)
   {
    Serial.println("SHARPLEFT");
    RightwheelslowForward();
    LeftwheelslowBackward();
   delay(50);
 }

else 
   {
      RightwheelStop();
       LeftwheelStop();
        delay(20); 
   } 

    
}
void RightwheelForward()
{
 Rwheel.write(45);
 delay(20);
}

void LeftwheelForward()
{
Lwheel.write(135);
delay(20);
}

void RightwheelBackward()
{
 Rwheel.write(135);
 delay(20);
}

void LeftwheelBackward()
{
 Lwheel.write(90);
 delay(20);
}

void RightwheelslowForward()
{
Rwheel.write(80);
delay(20); 
}
void LeftwheelslowForward()
{
Lwheel.write(100);
delay(20);
}

void RightwheelStop()
{
Rwheel.write(0);
delay(20); 
}

void LeftwheelStop()
{
Lwheel.write(0);
delay(20);
}

void RightwheelslowBackward()
{
Rwheel.write(100);
delay(20); 
}

void LeftwheelslowBackward()
{
 Lwheel.write(80);
 delay(20);
}

void ForwardAbit()
{
 RightwheelslowForward();
 LeftwheelslowForward();
 delay(2000);
}

kulaskugan1988:
my objective here is when my robot sense 4 lines it will stop and will not anymore go to any direction, regarding all data read which is a blackline.

Please don't double post.

What does your code actually do ?

...R

sorry for that.. my mistake.. its my 1st time here.. :frowning:

my objective here in my project is when my 5 sensors from left to right simultaneously detects blackline , my 2 servos will stop line following and stop at the current position.

thanks for the reply sir

kulaskugan1988:
my objective here in my project is when my 5 sensors from left to right simultaneously detects blackline , my 2 servos will stop line following and stop at the current position.

I understand the objective.

But you need to explain what the code actually does - I presume you have tried it ?

...R