qtr8a doesnt detect the white line

Hey guys,
I use arduino QTR library, I can’t read white line on a black surface.
I change the
readline(sensorvalues)
to
readline(sensorvalues,1)
But it’s still don’t detect the white line on black surface. I can read the black line on white surface, so I think problem isn’t about hardware,i think the problem about software.
What can I do?
I have a competition, this weekend :frowning:

Hello.

It looks like you did not set the second parameter (readMode) of readLine. The readLine function has three parameters: unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON, unsigned char whiteLine = 0. More details can be found under the “QTRSensors Methods & Usage Notes” section of the Arduino Library for the Pololu QTR Reflectance Sensors user’s guide.

If setting the readMode parameter of the readLine function does not fix the issue, can you post your entire code here so that I can see if there is something else wrong with your code?

- Amanda

ı added “QTR_EMİTTERS_ON” but still doesnt detect :(`

PIDeski.ino (4.1 KB)

#include <QTRSensors.h>

#define NUM_SENSORS             8 // number of sensors used
#define NUM_SAMPLES_PER_SENSOR  4  // average 4 analog samples per sensor reading
#define EMITTER_PIN             QTR_NO_EMITTER_PIN  // emitter is controlled by digital pin 2
#define kp 0.032
#define kd 0
#define ki 0.000
QTRSensorsAnalog qtra((unsigned char[]) {0, 1, 2, 3, 4, 5, 6, 7}, 
  NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
int dsv [NUM_SENSORS];

int sag_motor=11;
int sol_motor=10;
int in1=7;
int in2=12;
int in3=9;
int in4=8;
int trig=3;
int echo=2;
   
  int solhiz;
  int saghiz;
  int error;
  int lasterror;
  int base= 80;

   int derrivative;
  int integral=0;

long gidisgelis;
long uzunluk;
int i;

   
void ultrasoniksensoroku(){
  digitalWrite(trig, LOW);
  delayMicroseconds(1);
  digitalWrite(trig,HIGH);
  delayMicroseconds(1);
  digitalWrite(trig, LOW);
  gidisgelis= pulseIn(echo, HIGH);
  
  uzunluk = gidisgelis / 58.2;
// Serial.println(uzunluk);
}

 void sagileri(){
  digitalWrite(in1,HIGH); //SAG İLERİ
    digitalWrite(in2,LOW);
}

 void saggeri(){
  digitalWrite(in1,LOW); //SAG GERİ
    digitalWrite(in2,HIGH);
}

 void solileri(){
  digitalWrite(in3,LOW);   //SOL İLERİ
    digitalWrite(in4,HIGH);
 }

 void solgeri(){
  digitalWrite(in3,HIGH);   //SOL GERİ
    digitalWrite(in4,LOW);
    }


    
    
void setup() {

pinMode(echo,INPUT);
pinMode(trig,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(sag_motor,OUTPUT);
pinMode(sol_motor,OUTPUT);



 delay(500);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);    // turn on Arduino's LED to indicate we are in calibration mode
  for (int i = 0; i < 400; i++)  // make the calibration take about 5 seconds
  {
    qtra.calibrate();       // reads all sensors 10 times at 2.5 ms per six sensors (i.e. ~25 ms per call)
  }
  digitalWrite(13, LOW);     // turn off Arduino's LED to indicate we are through with calibration

  // print the calibration minimum values measured when emitters were on
  Serial.begin(9600);
  for (int i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(qtra.calibratedMinimumOn[i]);
    Serial.print(' ');
  }
  Serial.println();
  
  // print the calibration maximum values measured when emitters were on
  for (int i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(qtra.calibratedMaximumOn[i]);
    Serial.print(' ');
  }
  Serial.println();
  Serial.println();
  delay(1000); 
}

void loop() {

   digitalWrite(in1,HIGH); 
    digitalWrite(in2,LOW);
  digitalWrite(in3,LOW);
   digitalWrite(in4,HIGH);
 

  for(;;){
    unsigned int position = qtra.readLine(sensorValues,QTR_EMITTERS_ON,1);
  Serial.println(position);
for(i=0;i<NUM_SENSORS;i++){
  
  if(sensorValues[i]>= 70)
  dsv[i]=1;
  else
  dsv[i]=0;

 // Serial.print(dsv[i]);
}

Serial.println("");
if(dsv[0]== 0 && dsv[1]== 0 && dsv[2] == 0 && dsv[4]==1){
    while(dsv[4]=0){
     solileri();
     saggeri();
     analogWrite(sol_motor,70);
     analogWrite(sag_motor,70);
    }
   }
   else{

   if(dsv[7]== 0 && dsv[6]== 0 && dsv[5] == 0 && dsv[3] == 1){
    while(dsv[3] = 0){
    sagileri();
    solgeri();
    analogWrite(sag_motor,70);
     analogWrite(sol_motor,70);

    }
   }

 // Serial.println("pos  ");

 /* for (unsigned char i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(sensorValues[i]);
    Serial.print('\t');
  }
  Serial.println(); // uncomment this line if you are using raw values
  // comment this line out if you are using raw values
   delay(250);*/
   // Serial.println(position);
   

error= 3500 - position;
integral= integral+ error;
lasterror = error;
derrivative=(error- lasterror);
int motordv= (kp * error) + (kd * derrivative)+ (ki * integral);


solhiz= base + motordv;
saghiz= base - motordv;

if(solhiz>=255) solhiz=255;
if(solhiz<=0) solhiz=0;
if(saghiz>=255) saghiz=255;
if(saghiz<=0) saghiz=0;



 //  analogWrite(sag_motor,saghiz);
 //  analogWrite(sol_motor,solhiz);





   
     } }}

I briefly looked at your code and did not noticed anything obviously wrong. What Arduino board are you using to read the sensors on your QTR-8A? Are you moving all sensors across the black and white surfaces during calibration? Also, can you copy and paste the outputs of your Serial Monitor when running your code and post it here?

- Amanda

I figured out what was wrong, it seems that the cardboard I used was too reflective, even though it was black,the IR reflected. So the sensor read it was white.
Thanks for everything :slight_smile:

4 Likes

Hi yunus

My name is Alp. I’m from turkey. can you give me your email address?

I am glad you were able to get it working; thank you for letting us know what the issue was.

- Amanda