Line Follower Code HELP

Hello guys,
I have a 16 sensor line follower robot but my code is made for 8 sensored robots how can I modify it for 16 sensored robot and can I modify the code to "turn right when seeing two lines" ?

Posting the code you have would be a good start. It's impossible to say how best to modify something we've never seen.

Steve

Here is the code sorry for that.

fline8rc_siyah_zemin_beyazcizgi.ino (3.43 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please tell us your electronics, programming, Arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

Fast Line Follower Robot with PID Control from JSumo - YouTube here is the robot

Hi,

Can you please tell us your electronics, programming, Arduino, hardware experience?

Did you build the 16 sensor robot.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,

Can you please tell us your electronics, programming, Arduino, hardware experience?

Did you build the 16 sensor robot.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

I have built the robot it has arduino leonardo clone in it I don't have it's circuit blueprint.

meatlzero2:
I have built the robot

But did you write the code?

If you did I'm sure you would be able to modify it, so perhaps you didn't? (Nothing wrong with that, of course.) But hence the question about your Arduino programming experience.

#include <QTRSensors.h>

#define sagtabanhiz 100
#define soltabanhiz 100
#define sagmotoryon  13
#define sagmotorpwmpin 11
#define solmotoryon 12
#define solmotorpwmpin 3

#define mz80 14 //MZ80 A0 (14) numaralı pine bağlanmıştır.


QTRSensorsRC qtrrc((unsigned char[]) { 2, 4, 5, 6, 7 , 8, 9, 10} ,8, 2500, QTR_NO_EMITTER_PIN); 
unsigned int sensorValues[8];

void motorkontrol(int sagmotorpwm, int solmotorpwm){

  if(sagmotorpwm<=0) {
      sagmotorpwm=abs(sagmotorpwm);
      digitalWrite(sagmotoryon, LOW);
      analogWrite(sagmotorpwmpin, sagmotorpwm);
    }
  else {
      digitalWrite(sagmotoryon, HIGH);
      analogWrite(sagmotorpwmpin, sagmotorpwm);
  }
  if(solmotorpwm<=0) {
     solmotorpwm=abs(solmotorpwm);
     digitalWrite(solmotoryon, LOW);
     analogWrite(solmotorpwmpin, solmotorpwm);
    }
   else {
    digitalWrite(solmotoryon, HIGH);
    analogWrite(solmotorpwmpin, solmotorpwm);
   }
}


void frenle(){motorkontrol(0,0);}

void hafifsagadon(){motorkontrol(-100,100);}

void hafifsoladon(){motorkontrol(100,-100);}

void setup()
{
      delay(2000);
      pinMode(sagmotoryon, OUTPUT);
      pinMode(sagmotorpwmpin, OUTPUT);
      pinMode(solmotoryon, OUTPUT);
      pinMode(solmotorpwmpin, OUTPUT);
      int i;
      digitalWrite(13,HIGH);   
      digitalWrite(mz80,HIGH);    
     for (int i = 0; i < 200; i++)
     { 
         if ( 0 <= i && i < 5   )  hafifsagadon();       
         if ( 5 <= i && i  < 15   )  hafifsoladon(); 
         if ( 15 <= i && i < 25   )  hafifsagadon();       
         if ( 25 <= i && i < 35   )  hafifsoladon(); 
         if ( 35 <= i && i < 45   )  hafifsagadon();       
         if ( 45 <= i && i < 55  )  hafifsoladon(); 
         if ( 55 <= i && i < 65   )  hafifsagadon();       
         if ( 65 <= i && i < 75  )  hafifsoladon();
         if ( 75 <= i && i < 85   )  hafifsagadon();       
         if ( 85 <= i && i < 90  )  hafifsoladon();
  
         if ( i >= 90  )  {frenle(); delay(5);}
        
       qtrrc.calibrate(); 
       delay(4);
      } 
    digitalWrite(13,LOW);
    delay(2000);
//    motorkontrol(200,0);
//    delay(5000);
//    motorkontrol(0,200);
//    delay(5000);
//     motorkontrol(-200,-200);
//    delay(5000);
    Serial.begin(9600);
} 

int sonhata = 0;
float Kp = 0.06;
float Kd = 0.8;

int sagmotorpwm = 0;
int solmotorpwm = 0;
int zemin=1;

void loop()
{ 

  while (digitalRead(mz80)==0) {
     analogWrite(sagmotorpwmpin, 0);
      analogWrite(solmotorpwmpin, 0);   
      delay(250); 
  }
  // Pozisyon hesabı QTRlibrary tarafından yaptırılıyor
  unsigned int sensorValues[8];   
  unsigned int position = qtrrc.readLine(sensorValues,1,zemin); 
  int hata = position-3500;

 
  //////////// motorlara verilecek hız düzeltme oran hesabı
  int duzeltmehizi = Kp * hata + Kd*(hata - sonhata);
  sonhata = hata;
    
   
  //////////// Motorlara uygulanacak kesin hız ayarları
   sagmotorpwm = sagtabanhiz + duzeltmehizi  ;
   solmotorpwm = soltabanhiz - duzeltmehizi  ;
  
   sagmotorpwm = constrain(sagmotorpwm, -250, 200); ///// Burada motorlara uygulanacak PWM değerlerine sınırlandırma getirilmiştir.
   solmotorpwm = constrain(solmotorpwm, -250, 200); 
   motorkontrol(sagmotorpwm,solmotorpwm);
  //   Seri monitörde hata, sağ ve sol motor hız değerlerini gösternek için alttaki satırı aktif yapınız
  //   Serial.print(hata);  Serial.print(" "); Serial.print(sagmotorpwm); Serial.print(" "); Serial.println(solmotorpwm); delay(100);  

}
// Motor kontrol alt programı