Unexpected results from QTR-1RC on Arduino

Hi, I’ve been playing around with my Arduino Uno and a couple of QTR-1RC sensors today, using the QTRSensors library. Everything seemed to be working as expected, but no matter what I put in front of either sensor, the values returned from the sensor are always within a very small range (between 4 and 12, usually 8). The range I’m expecting is 0 - 1000.

The pins were connected to GND, 5V and digital 2.

Here’s my sketch:

#include <QTRSensors.h>

#define SENSOR_PIN 2
QTRSensorsRC qtr((unsigned char[]) {SENSOR_PIN}, 1, 1000);

unsigned int sensorValues[1];
void setup()
{
  Serial.begin(9600);
  pinMode (SENSOR_PIN, INPUT);
  
  int i; 
  for (i = 0; i < 250; i++) // make the calibration take about 5 seconds 
  { 
    qtr.calibrate(); 
    delay(20); 
    Serial.println("calibrating");
  }
}

void loop()
{
  qtr.read(sensorValues);
  Serial.print(sensorValues[0]); 
  if ((sensorValues[0] >= 0) && (sensorValues[0] <= 500))
  {
    Serial.print(" High Reflectance ");
  }
  else
  {
    Serial.print(" Low Reflectance ");
  }
  Serial.println();
  delay(250);
}

Is there anything I’m missing that might be causing the odd results?

Sorry if this question is a duplicate, it wasn’t possible to search for ‘QTR-1RC’.

Hello.

I am sorry you are having problems with your QTR sensors. Could you try running the QTRRCRawValuesExample to test the sensors? Could you also post pictures of your setup?

- Jeremy

It took a while of trying several things out, but I just got it working perfectly a few moments ago by using digital pin 5 rather than pin 2. I read a variety of things here that helped me along the way. I’m very pleased with myself now. :mrgreen:

Thanks for letting us know. I am glad you got it working.

- Jeremy