Go Down

Topic: Have problem with Line follower project. (Read 45 times) previous topic - next topic

lahariv

Please check I'm trying to do a line follower I have made the connections as below:

Motor shield(L293D) fit on Arduino
DC motors are connected to M1 +- and M2 +- Motor Shield
Servo 0 pins connected to IR sensor pins and it's o/p A0
Servo 1 pins connected to IR sensor pins and it's o/p A0
And power supply given to Motor shield board with 4 AA batteries.

Program:


//Line-follower Robot using Arduino Uno and Motor Shield

//library for DC motor
#include<AFMotor.h>

//defining the two motors
AF_DCMotor motor1(1,MOTOR12_64KHZ);
AF_DCMotor motor2(2,MOTOR12_64KHZ);

//declaring Sensor Pins.
int LeftSensor=A0;
int RightSensor=A1;
int L_sensor_val=0;//to store value from sensors.
int R_sensor_val=0;

int threshold=500;

void setup() {
               motor1.setSpeed(255);
               motor2.setSpeed(255);
               //set the speed to 200/255
}
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) {
                          motor1.run(FORWARD);
                          motor2.run(FORWARD);
       }
    if (L_sensor_val < threshold && R_sensor_val < threshold) {
                          motor1.run(BACKWARD);
                          motor2.run(BACKWARD);
      }
    if (L_sensor_val < threshold && R_sensor_val > threshold) {
                        motor1.run(BACKWARD);
                        motor2.run(FORWARD);
      }
    if (L_sensor_val > threshold && R_sensor_val < threshold) {
                       motor1.run(FORWARD);
                       motor2.run(BACKWARD);
      }
 
}



Problem:

Line follower is just moving forward but doesn't do anything, when sensor light switches ON the motor isn't stopping, same with both sensors.

How to check sensor readings, to check if the sensors are working?

Does it matter which servo pins are connected to which arduino pins?

Is there anything wrong with the program?


Please help me with this.

Go Up