Servo Motors and Path Following

Hi,

I am trying to construct a simple path following robot using servos and IR sensors. I wanted to know how I should approach this as most path following robots are constructed using DC motors and drivers.

Which Libraries should I incorporate and commands should I use.

Thank you.

So you mean servos, or continuous rotation ex-servos?

Servos are typically used for angular positioning of the output , for driving wheels a motor/gearbox is the better solution .

You are starting the wrong way. First You need a strategy that You know can work. Then You can start buying stuff.
Path following using IR sounds bad to me. How will You create IR radiating lines, points....?

I plan to use continuous servos for just basic black line following.

Hey, hey, hey. Slow down. First You talk about IR, then You tell about a servo following a black line. Such servos does not exist.

Take down Your project into small parts. First make the line recognizing stuff work. Then make the stearing work and then the drive motor controll.

Continuous servos are DC motors with gearboxes and their own driver.

You normally drive them with the Servo library. write(90) is stop, write(0) full speed one way, write(180). Anything else you need?

Steve

Hers is the code I created:

// This code utilizes two servos and two infrared sensors for basic line following
# include <Servo.h>
Servo ServoL;
Servo ServoR;

#define SensorL 8
#define SensorR 7

int ResultL;
int ResultR;

void setup() {
  // put your setup code here, to run once:

  ServoR.attach(9);
  ServoL.attach(10);

  pinMode(SensorL, INPUT);
  pinMode(SensorR, INPUT);
  Serial.begin(9600);

}

void loop() {
  ResultR = digitalRead(SensorR);
  Serial.println("Right Sensor is Reading");
  ResultL = digitalRead(SensorL);
  Serial.println("Left Sensor is Reading");
  //
  if (ResultR == LOW && ResultL == LOW) {
    ServoL.write(88);
    ServoR.write(88);
  }

  else if (ResultR == HIGH && ResultL == LOW) {
    ServoL.write(88);
    ServoR.write(90);
  }

   else if (ResultR == LOW && ResultL == HIGH) {
      ServoL.write(90);
      ServoR.write(88);
    }
    else {
      ServoR.write(90);
      ServoL.write(90);
    }
    delay(10);
  }

I think it makes sense for path following. But let me know if you think otherwise.

You keep writing about IR sensors and a black line. The black line is what you are seeing. Have you tested it under IR light to determine if it is still black? IF it is a good reflector of IR, it will be the same as we see white.

Paul

Compile, download and run and see what happends. No need for anybody to analyze and think. Code has no beautypoints. If it does what is wanted, it is good code.

@Paul_KD7HB
Some OPs are good in writing but unable to read answers and respond. I'll look for next OP...