Problem in adding the programme of line follower and obstacle avoider

Thread Starter

nisha03

Joined May 24, 2017
3
hello..respected sir
i am making line follower follower with obtacle avoider robot using arduino uno. i done 90% of work. my robot run when i apply the line follower program and also detect the object when i run obstracle program in that but now i want add both programme...i am actully new in arduino so having little knowlagde about programming n arduino so guide me...the programming of my robot is given below

line follower programme:
C:
/*-------definning Inputs------*/
#define LS 6  // left sensor
#define RS 7  // right sensor
/*-------definning Outputs------*/
#define LM1 2  // left motor
#define LM2 3  // left motor
#define RM1 4  // right motor
#define RM2 5   // right motor

void setup()
{
  pinMode(LS, INPUT);
  pinMode(RS, INPUT);
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
}

void loop()
{
  if(digitalRead(LS) && digitalRead(RS))  // Move Forward
  {
  digitalWrite(LM1, HIGH);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, HIGH);
  digitalWrite(RM2, LOW);
  }
 
  if(!(digitalRead(LS)) && digitalRead(RS))  // Turn right
  {
  digitalWrite(LM1, LOW);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, HIGH);
  digitalWrite(RM2, LOW);
  }
 
  if(digitalRead(LS) && !(digitalRead(RS)))  // turn left
  {
  digitalWrite(LM1, HIGH);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, LOW);
  digitalWrite(RM2, LOW);
  }
 
  if(!(digitalRead(LS)) && !(digitalRead(RS)))  // stop
  {
  digitalWrite(LM1, LOW);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, LOW);
  digitalWrite(RM2, LOW);
  }
}

obstracle avoider programme:
const int trigPin = 11;
const int echoPin = 10;
const int in1 = 2;
const int in2 = 3;
const int in3 = 4;
const int in4 = 5;


void setup()
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode (in1, OUTPUT);
  pinMode (in2, OUTPUT);
  pinMode (in3, OUTPUT);
  pinMode (in4, OUTPUT);
}
long duration, distance;

void loop()
{ 
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW); 
  duration = pulseIn(echoPin, HIGH);
  distance = duration/58.2;
  if(distance<15)
  {
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  }
  else
  {
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  } 
  delay(50);
}
Thank you.....

Moderators note: used code tags
 
Last edited by a moderator:

Thread Starter

nisha03

Joined May 24, 2017
3
thanks for the suggestion...i do that and the program is right now after compiled it in arduino software but now after ignoring the object on black line my robot don't come back on the line again so now what should i do??? is any other code for it???
 
Now you must write a procedure for the robot to actually find a line. Everytime the robot is not on the line, what is the robot going to do in order to try to find it? This will depend on the parameters of the line and obstacles.

What do you do when you detect an obstacle? Maybe always turn right. Then at some point you may expect to have to turn left in order to find the line.
 
Top