Line following with multiple sensors


#1

Hi,

I was unable to figure out how (if it possible at all ) can I read multiple line following sensors, so at the end I used the digitalRead function to read 6 sensors separately connected to 3 dual ports (3,4 and 6). Originally I wanted some kind of PID control but this semi PID seems to be working fine.
This uses a simple weighting and calculates difference between sensor on the right and left, if line is lost (all sensors output 1) uses the last known values to steer back towards the line.

Have fun :slightly_smiling:

#include "MeOrion.h"
MeDCMotor motor1(M1);
MeDCMotor motor2(M2);
int LSpeed = 0;
int RSpeed = 0;
int Speed = 105;
int l1=1;
int l2=1;
int l3=1;
int l4=1;
int l5=1;
int l6=1;
int left=100;
int right=100;
int diff=0;
int pdiff=0;
int sum=0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
   l1=digitalRead(12);
   l2=digitalRead(13);
   l3=digitalRead(8);
   l4=digitalRead(2);
   l5=digitalRead(A2);
   l6=digitalRead(A3);
   sum=l1+l2+l3+l4+l5+l6;
   left=65*l1+25*l2+1*l3;
   right=65*l6+25*l5+1*l4;

   if  (sum == 6 ) {
      diff = pdiff;
   } else {
   diff=right-left;
   pdiff=diff;
   }
   
   RSpeed=Speed+diff;
   LSpeed=Speed-diff;
   
   
  
  Serial.print(pdiff);Serial.print("__");Serial.print(sum);Serial.print("_left:_");Serial.print(LSpeed);Serial.print("_right:_");Serial.println(RSpeed);

  motor1.run(RSpeed);
  motor2.run(LSpeed);
 
  delay(20);
}

#2

What was the performance like? Was it better than a dual Line Follower sensor?


#3

Hi, I dont really know, never tried that one.


#4