QTR-1RC Not Working with library

Hi all,

Have something strange happening using the QTR library with a single QTR1C sensor. I modified the example code for raw values like:

#define NUM_SENSORS   1     // number of sensors used
#define TIMEOUT       2500  // waits for 2500 microseconds for sensor outputs to go low
#define EMITTER_PIN   QTR_NO_EMITTER_PIN     // emitter is controlled by digital pin 2

// sensors 0 through 7 are connected to digital pins 3 through 10, respectively
QTRSensorsRC qtrrc((unsigned char[]) {5},
  NUM_SENSORS, TIMEOUT, EMITTER_PIN); 
unsigned int sensorValues[NUM_SENSORS];


void setup()
{
  delay(500);
  Serial.begin(9600); // set the data rate in bits per second for serial data transmission
  delay(1000);
}


void loop()
{
  // read raw sensor values
  qtrrc.read(sensorValues);

  // print the sensor values as numbers from 0 to 2500, where 0 means maximum reflectance and
  // 2500 means minimum reflectance
  for (unsigned char i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(sensorValues[i]);
    Serial.print('\t'); // tab to format the raw data into columns in the Serial monitor
  }
  Serial.println();
  
  delay(250);
}

The values printed are either 4 or 8, mostly 8’s. I did a search of the forum and came across this post that implements reading the sensor without the library, https://forum.pololu.com/t/code-snippet-for-qtr-1rc/3548 and gave it a try with the same hardware setup and it appears to be working, depending on the reflectance the values are changing. Here is the code that seemed to work based on the reference link.

unsigned long startTime;
unsigned long elapsedTime;

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

void loop() {
{ 
//************* Read One Sensor and Display Value on LCD 
  pinMode(5, OUTPUT);       // Set sensor pin to output
  digitalWrite(5, HIGH);
  delayMicroseconds(50);          // Charge capacitor for 50 usec
  pinMode(5,INPUT);         
  digitalWrite(5, LOW);     
  startTime = micros();
  while(digitalRead(5) == HIGH)
  {       
  }
  elapsedTime = micros() - startTime;
  Serial.println(elapsedTime);
}
}

I would rather use the library.

Any suggestions? Thanks
Mike

Hello, Mike.

I looked over your code and did not see anything wrong with it. Have you tried running the example code as is? If not, can you load the unmodified sketch onto your Arduino board, move the sensor across your line, and post a screenshot of the Serial Monitor here? Did you execute the same test with both codes? Can you post pictures of your setup and test surface? Also, which Arduino board are you using?

- Amanda

Hi Amanda,
Thanks for getting back to me. Here is the info you requested.

Have you tried running the example code as is? Yes I have a couple of times.

And post a screenshot of the Serial Monitor here:

Did you execute the same test with both codes? Yes same test was done with both codes.

Can you post pictures of your setup and test surface?
image

Running on a Arduino Uno. Test pattern is printed on plain white paper. Start on white when sketch starts and then slides over sensor.

Thanks
Mike

Hi Amanda

Think I got the issue resolved with the example. In looking a little more closely at the code snippet that I used and the example I noticed the timeouts were different. In the example it is set at 2500 micros and the snippet was at 5000 micros. I changed the timeout to 5000 and the example started working no problem. Going to play a little more with the examples and if I run into any other issue I will let you know.

Thanks for listening.
Mike

UPDATE: Think I spoke to soon. Went to run the calibrate sketch and that failed even with increasing the timeout. I went back and reran the rawvalues sketch from the library and it started doing the same thing with all 8’s and 4’s. Not sure whats going on.

Hi, Mike.

It sounds like there might be something wrong with your connection to the QTR sensor array. Can you post close-up pictures showing your connections between the Arduino Uno and QTR board? Also, can you try running the other code and post its output here?

-Amanda

Hi Amanda
Sorry for not getting back to you sooner but was tied up with something yesterday. Anyway here are some detailed photos of the wiring:
20171219_102854
20171219_103050
20171219_103050

Not sure how the wiring can be messed us since its working with the other sketch. Here is a same output of the transitions:

3160
3164
3168
3152
3172
3164
3164
3160
3144
3144
3132
3132
3108
3108
3112
3100
3100
3084
3092
3088
3096
3100
3088
3084
3068
3052
3052
3072
3068
3064
3068
3052
3032
3004
3000
2984
2968
2988
3016
3032
3040
3060
3080
3092
3072
3064
3036
2980
2952
2920
2868
2828
2772
2724
2696
2680
2664
2656
2660
2656
2636
2616
2596
2548
2508
2456
2384
2320
2212
2136
2056
1980
1932
1904
1892
1896
1892
1904
1920
1920
1916
1900
1844
1788
1728
1672
1616
1544
1484
1416
1344
1284
1224
1176
1132
1092
1056
1028
1012
1000
1004
1008
1012
1004
988
972
948
924
896
864
832
804
784
768
760
752
744
748
752
752
756
756
752
744
740
732
720
704
692
684
676
676
676
676
676
668
660
652
640
624
612
592
580
564
552
544
540
536
532
532
532
532
528
524
512
504
496
484
468
456
444
436
424
416
408
404
400
392
388
388
384
388
392
400
408
408
412
408
404
396
384
376
368
360
352
344
340
336
328
328
324
324
324
324
320
316
308
296
292
288
284
288
292
296
296
304
312
316
320
324
328
328
328
320
312
308
296
296
296
300
300
304
308
308
312
312
312
312
316
312
312
308
304
304
304
304
304
308
316
328
336
344
352
356
352
352
352
348
344
344
336
332
332
340
344
356
368
376
388
392
392
392
392
392
392
392
392
392
392
384
392
392
404
412
424
424
424
424
420
416
412
408
408
408
408
412
416
420
424
436
432
440
444
448
452
452
460
464
468
472
480
488
496
500
508
508
504
504
496
492
492
488
488
484
484
484
488
492
500
508
516
528
536
544
548
548
556
556
556
556
552
552
552
556
556
556
560
560
564
564
564
568
572
568
568
564
560
560
560
560
560
560
564
564
564
568
572
576
576
576
580
580
580
580
584
592
596
596
604
604
608
612
620
624
628
628
628
632
636
644
644
648
648
644
636
644
640
636
632
632
632
636
644
644
644
652
648
648
640
628
628
624
628
628
628
628
628
628
624
620
616
612
612
612
612
608
604
600
600
604
608
612
620
624
628
624
620
612
608
604
596
596
592
588
588
588
588
592
596
600
608
612
616
616
620
624
624
624
624
624
624
620
616
616
620
628
628
636
644
648
652
652
660
660
668
668
668
664
664
660
656
656
660
660
664
664
668
672
672
672
676
676
676
672
668
668
664
664
668
672
676
684
692
700
708
720
720
724
732
736
732
736
736
740
744
752
756
764
768
780
784
784
780
776
772
772
768
772
780
788
800
808
816
820
832
840
844
848
856
860
864
864
864
864
868
868
872
880
892
904
912
932
956
984
1012
1052
1092
1120
1136
1144
1136
1136
1136
1120
1112
1108
1116
1136
1160
1180
1204
1220
1232
1248
1248
1256
1256
1256
1248
1224
1204
1192
1180
1168
1152
1144
1136
1124
1120
1108
1100
1096
1080
1080
1076
1068
1064
1056
1044
1048
1048
1056
1060
1064
1072
1072
1068
1072
1060
1044
1032
1008
988
972
960
952
940
924
916
908
908
900
896
896
900
896
896
892
888
884
876
868
864
864
864
864
864
868
876
888
896
908
924
928
932
932
928
932
932
924
920
920
920
920
916
912
912
916
920
920
920
920
912
908
892
896
896
896
896
896
900
908
924
936
956
972
988
1004
1004
1004
1004
996
996
992
988
984
988
992
996
1000
1012
1024
1032
1044
1048
1044
1044
1032
1012
1004
988
980
980
980
980
984
992
992
996
1004
1004
1004
1000
996
996
1000
996
996
996
980
976
972
972
960
964
948
944
940
932
924
920
912
904
900
900
900
900
904
912
916
920
916
920
924
928
936
944
952
956
948
944
940
940
940
940
948
956
956
960
960
956
952
952
952
956
960
960
960
960
972
976
988
1008
1020
1028
1036
1032
1028
1028
1028
1032
1028
1024
1020
1020
1028
1032
1048
1060
1068
1076
1084
1076
1072
1072
1064
1064
1072
1072
1072
1076
1088
1104
1120
1136
1136
1148
1156
1164
1168
1176
1196
1216
1228
1244
1264
1276
1276
1280
1276
1276
1272
1260
1244
1232
1216
1200
1180
1160
1144
1132
1112
1088
1076
1064
1048
1052
1056
1068
1072
1072
1080
1092
1116
1136
1152
1184
1216
1256
1308
1376
1448
1520
1592
1668
1748
1812
1852
1884
1916
1960
1980
2000
2020
2028
2032
2028
2020
2020
2000
1968
1940
1920
1916
1924
1952
1972
1976
1980
1980
1968
1944
1916
1904
1884
1872
1880
1888
1904
1928
1964
2000
2048
2096
2144
2180
2220
2272
2320
2360
2380
2392
2412
2436
2436
2440
2444
2444
2448
2448
2456
2476
2492
2520
2544
2556
2580
2592
2600
2612
2600
2600
2596
2592
2596
2588
2600
2616
2612
2612
2600
2600
2596
2564
2536
2508
2464
2424
2384
2364
2336
2284
2244
2208
2164
2124
2092
2064
2040
2032
2012
1976
1920
1856
1780
1692
1612
1524
1440
1360
1292
1232
1172
1116
1060
1016
984
968
944
928
908
884
860
836
808
772
736
696
660
620
584
552
528
504
480
456
436
416
396
380
368
360
360
356
360
360
352
344
332
316
304
292
284
276
272
268
268
268
268
272
272
272
276
272
268
264
252
248
232
236
236
236
236
236
236
236
232
228
228
224
220
216
216
212
212
204
196
188
180
176
176
176
176
176
176
176
176
176
176
176
176
176
176
176
176
176
176
176
176
172
176
172
172
172
172
172
172
180
172
176
172

Hope this helps.

MIke

Thanks for posting better pictures of your setup. Your soldering and connections look fine from what I can see. Can you verify that the wire connected to the OUT pin on the QTR sensor is connected to pin 5 on your Arduino board?

How are you testing the QTR sensor? Are you sliding the test surface (or paper) over the sensor? It would be best if you can post a video showing your test procedure.

- Amanda