# Line Follower to follow 90 degree angle line

Hello,
I want to make a line follower robot that is able to follow a line which turns at 90 degrees. I have 2 IR sensors only though.
Is it possible to do so. If it is, can anyone please suggest some code?

How well does your code work now? Does it work for a straight line? You need to decide how sharp of a right angle turn you are trying to follow.

Paul

My code works for a straight line, and for small turns too.

``````const int righto = 8;
const int lefto = 7;
const int motor_rightFront = 2;
const int motor_rightBack = 3;
const int motor_leftFront = 4;
const int motor_leftBack = 5;
int x;
int y;
void setup() {
// put your setup code here, to run once:
for(x = 2; x<6; x++){
pinMode(x, OUTPUT);
}
for(y=7; y<9 ; y++){
pinMode(y, INPUT);
}
}

void loop() {
// put your main code here, to run repeatedly:
if(right_sensor == HIGH && left_sensor == LOW){
yay();
delay(200);
left();
delay(200);
}
if(right_sensor == LOW && left_sensor == HIGH){
yay();
delay(200);
right();
delay(200);
}
if(right_sensor == LOW && left_sensor == LOW){
yay();
}
if(right_sensor == HIGH && left_sensor == HIGH){
forward();
}
}
void right(){
digitalWrite(motor_rightFront, LOW);
digitalWrite(motor_rightBack, LOW);
digitalWrite(motor_leftFront, LOW);
digitalWrite(motor_leftBack, HIGH);
}
void left(){
digitalWrite(motor_rightFront, LOW);
digitalWrite(motor_rightBack, HIGH);
digitalWrite(motor_leftFront, LOW);
digitalWrite(motor_leftBack, LOW);
}
void forward(){
digitalWrite(motor_rightFront, LOW);
digitalWrite(motor_rightBack, HIGH);
digitalWrite(motor_leftFront, LOW);
digitalWrite(motor_leftBack, HIGH);
}
void yay(){              //This is to make it stop.
digitalWrite(motor_rightFront, LOW);
digitalWrite(motor_rightBack, LOW);
digitalWrite(motor_leftFront, LOW);
digitalWrite(motor_leftBack, LOW);
}
``````

I want it to be able to follow a sharp 90 degree angle. If that is not possible, then I do not mind a slight curve too.

I could be missing something glaringly obvious but if you have 2 sensors sweeping back and forth to track a line and you come to a 90 degree turn, 1 sensor will suddenly hit the line and the other will not. This should still adjust left or right as the situation calls for. The only difference is the severity of onset of the line. If the angle is steep, the voltage on your sensor will change rapidly. If the angle is shallow, the voltage will change gradually. You could define regimes for the slew rate of your sensor voltage that could be mapped to the turn angle.