Menu Close

Line Follower on Robo India Da Vinci Robot

Robo India presents Line follower on Arduino Platform using motor shield and Da Vinci Robot.

 Buying links – You May buy this kit from our store, It is available with original Arduinio UNO Board.

http://roboindia.com/store/line-follower-da-vinci

1. Introduction:

A step by step guide for to make line follower using Robo India’s Motor Shield and Da Vinci Robot.

Attach 20 CM wires to motors and battery holder. There are two colored wire for your convenience to identify positive and negative terminal so don’t use same color wires on a single device.

You may need this tutorial to assemble Da Vinci Robot. While you assemble Da Vinci Robot. Mark Name on wires so that you can identify them after assembly.

1.2 The motor shield Introduction 

 Robo India offers Arduino compatible Motor shield that can run 2 servo and 2 stepper or 4 DC motor. This shield uses shift register IC. Data is given in serial mode that is converted to parallel by this shift register IC. Connection are as follows.

Board to Shift Register-

  • Digital Pin 8 – Data Pin
  • Digital Pin 12 – Latch Pin
  • Digital Pin 4 – Clock Pin
  • Digital Pin 7 – Enable Pin

Shift Register to Motors-

  • Q0 – M3 A
  • Q1 – M2 A
  • Q2 – M1 A
  • Q3 – M1 B
  • Q4 – M2 B
  • Q5 – M4 A
  • Q6 – M3 B
  • Q7 – M4 B

2. Assembly and Connections

After assembling the robot make the connection as given in the following diagram. The Power Jumper on the motor shield works as Switch to motor it will be useful while debugging.You may add a back light LED it is completely optional and does not included in the KIT. The function of Back Light LED is, It glows when robot stops. And it is OK if you don’t attach one. 

Make the connection as shown above. 

2.1 Testing motor Connection

It is difficult to find GND and positive supply terminal of motor. Transfer the following code to the Arduino Board. The robot should move in forward direction, if it not doing so, interchange the of the wire of motor. e.g. suppose left motor is rotating in back ward direction and right motor is rotating in forward direction then you have to interchange the wires of M3 terminal.

You may download this sketch from here.

//Robo India Line follower Tutorial
// This codes runs robo int the forward direction.

// Shield Pins Declaration 
int dataPin = 8;        
int latchPin = 12;
int clockPin = 4;
int en = 7;
void setup()
{
    pinMode(dataPin, OUTPUT);     // Setting up the motor shield. 
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(en, OUTPUT);    
    digitalWrite(en, LOW); 
 
 forward(); // This funtion for forward robot motion
 
  
 }

void loop()
{
}

void forward(void){
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 3);
        digitalWrite(latchPin, HIGH);  

}

void backward(void){
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 164);
        digitalWrite(latchPin, HIGH);  
}

void turn_left(void){
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 161);
        digitalWrite(latchPin, HIGH);  
}

void turn_right(void){
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 38);
        digitalWrite(latchPin, HIGH);  
}

void halt(void){
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 32);
        digitalWrite(latchPin, HIGH);  
}


2.2 Programming Line Follower 

Till the above step you have made all of the connection and your motors are connected to the correct terminals. The following programme is the line following programme.

It has following predefined function for robot motion-

1. forward() : forward movement of robot.

2. backward() : backward movement of robot.

3. turn_left() : for turning left.

4. turn_right(): for turning right.

5. halt() : for stopping robot.

You may download this sketch from here.

// Robo India Line Follower Tutorial.

// declaring Shield
int dataPin = 8;        
int latchPin = 12;
int clockPin = 4;
int en = 7;
// declaring Sensor Pins.
int LeftSensor = A1;
int RightSensor = A0; 
int L_sensor_val = 0; // To store value from sensors. 
int R_sensor_val = 0; 

int threshold = 300; // Threshold value to distinguish black and white. 

void setup()
{   // setting up shield. 
    pinMode(dataPin, OUTPUT);      
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(en, OUTPUT);    
    digitalWrite(en, LOW);   

}

void loop()
{
L_sensor_val =  analogRead(LeftSensor);   // Reading Left sensor data
R_sensor_val =  analogRead(RightSensor);  // Reading Right sensor data


  if(L_sensor_val<threshold && R_sensor_val>threshold) {  // testing for left turn
    while (L_sensor_val<threshold && R_sensor_val>threshold){
      turn_right();  
      L_sensor_val =  analogRead(LeftSensor);
      R_sensor_val =  analogRead(RightSensor);
    }
  }
  else if(L_sensor_val>threshold && R_sensor_val<threshold){  // tesing for right turn
    while (L_sensor_val>threshold && R_sensor_val<threshold){
      turn_left();
      L_sensor_val =  analogRead(LeftSensor);
      R_sensor_val =  analogRead(RightSensor);
    }
 }
forward(); // Default movement is forward.
}

void forward(void){  // function for forward movement. 
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 3);
        digitalWrite(latchPin, HIGH);  

}

void backward(void){   // function for forward movement. 
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 164);
        digitalWrite(latchPin, HIGH);  
}

void turn_left(void){   // function for left turn. 
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 161);
        digitalWrite(latchPin, HIGH);  
}

void turn_right(void){   // function for Right turn. 
        digitalWrite(latchPin, LOW);            
        shiftOut(dataPin, clockPin, LSBFIRST, 38);
        digitalWrite(latchPin, HIGH);  
}

void halt(void){        // function for stopping robot. 
        digitalWrite(latchPin, LOW);             
        shiftOut(dataPin, clockPin, LSBFIRST, 32);
        digitalWrite(latchPin, HIGH);  
}


once you have transferred this code to the the Arduino board. Your robot is ready to follow the line. Put the robot on a white line of thickness 25 – 30 mm. The back ground is to be black.

Da vinci robot looks like –

Line follower in action –

Resources:

Robo India Motor Control Tutorial on Arduinio.

This motor shield is based on Adafruit Motor Shield. Resources can be found here.

Buying links – You May buy this kit from our store, It is available with original Arduinio UNO Board.

http://roboindia.com/store/line-follower-da-vinci

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
http://roboindia.com

Leave a Reply