Line Following Robot with boltduino

Please provide code of line following robot using IR modules and boltduino.

@ashwin.salgaocar Can you please look into this?

Hi @shraddhaachavan2000 We have not covered the Line Following Robot in the robotics training and hence we will not be able to provide the code for the same. The reason it was excluded is that we had noticed that it was very much dependent on the light conditions of the environment. The same code which would work in the morning would not have worked in the evening due to differences in the lighting.

Thanks @ashwin.salgaocar sir for clearing this can I have another solution for this problem.

1 Like

@shraddhaachavan2000

A regular LFR code on Arduino works with Boltduino as well. Please refer to the below code:

int irA; //left
int irB; //right

void setup()
{
  pinMode(8, INPUT); //Left IR Sensor
  pinMode(9, INPUT); //Right IR Sensor
  
  //Motor Driver connections
  pinMode(4,OUTPUT);                // IN1
  pinMode(5,OUTPUT);                // IN2
  pinMode(6,OUTPUT);                // IN3
  pinMode(7,OUTPUT);                // IN4
}

void loop()
{
  irA= digitalRead(8);
  irB= digitalRead(9);

  //Serial.print(irA);
  //Serial.print(" ");
  //Serial.println(irB);
  
  if ((irA == 0) && (irB == 0)){
    forward();
    //Serial.println("Forward");

  }
  
 else if ((irA == 1) && (irB == 1)){
    stop();
     //Serial.println("Stop");
  }
  
  else if ((irA == 1) && (irB == 0)){
    left();
    //Serial.println("Left");
  }
  
  else if ((irA == 0) && (irB == 1)){
    right();
    //Serial.println("Right");
  }  
} 



void forward(){
  digitalWrite(4,HIGH);      
  digitalWrite(5,LOW);          
  digitalWrite(6,HIGH);         
  digitalWrite(7,LOW);  
}

void left(){
  digitalWrite(4,HIGH);          
  digitalWrite(5,LOW);         
  digitalWrite(6,LOW);         
  digitalWrite(7,LOW);  
}

void right(){  
  digitalWrite(4,LOW);          
  digitalWrite(5,LOW);        
  digitalWrite(6,HIGH);         
  digitalWrite(7,LOW); 
}

void stop(){
    digitalWrite(4,LOW);         
    digitalWrite(5,LOW);          
    digitalWrite(6,LOW);          
    digitalWrite(7,LOW);  
}
1 Like

Thank you @akshayan.sinha