Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

QTRXL-HD-01A Long Range returning strange values


#1

I just switched to this sensor, and believe I have wired it up correctly. When I read() the value, however, it usually returns 1024. If I press it very close to a piece of white paper, I can get a value as low as 947 or so. I’m confused because I thought 1023 was the highest value, and I am expecting lower values with white paper.

Here’s an album with my wiring: https://photos.app.goo.gl/Abwi3yhqrbHV8TC56

The sensor pin is wired to 0,
The ground is wired to pin 13 which is pulled low.

Here is my output:
"

1023 
1024 

1024	
1024	
1024	
1024	
1024	
1024	
1024	
1024	
1024	
1024	
1024	
987	
1024	
1024	
1024	
1024	
1024	
1024

"

I’m doing raw reads here:

#define NUM_SENSORS             1  // 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

// sensors 0 through 5 are connected to analog inputs 0 through 5, respectively
QTRSensorsAnalog qtra((unsigned char[]) {0},
  NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];


void setup()
{
  delay(500);


  // TURN ON PINS FOR QTR SENSOR
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  for (int i = 0; i < 400; i++)  // make the calibration take about 10 seconds
  {
    qtra.calibrate();       // reads all sensors 10 times at 2.5 ms per six sensors (i.e. ~25 ms per call)
  }

  // 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()
{
   qtra.read(sensorValues);

  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

  delay(250);
}

#2

Hello.

From your code, it looks like you are using the wrong QTR object for your QTRXL-HD-01A sensor; you should be using QTRDimmableAnalog, not QTRSensorsAnalog. You can find more details about the QTRDimmableAnalog class and its methods under the “QTRSensors Methods & Usage Notes” section in the Arduino Library for the Pololu QTR Reflectance Sensors.

- Amanda


#3

Thanks for the reply! I tried switching to Dimmable, but it exhibits the exact same behavior.


#4

I tested your code using an A-Star 32U4 Micro and was able to get meaningful readings. (I modified your code slightly by changing the ground connection from pin 13 to pin 12 and using the correct QTR object as mentioned in my previous post.)

I looked into your Adafruit Feather HUZZAH ESP8266 board further and found the following under the “Analog Pins” description of the “Pinouts” section in its tutorial:

You will need to add a voltage divider, since you’re powering the sensor board with 3.3V from your Feather board. However, I suspect the voltage divider would not work well because the sensor has a high output impedance, making it difficult to measure the signals accurately. You could try adding the voltage divider and see if it works fine for your setup and application. Otherwise, an RC sensor might work better.

- Amanda


#5

OK, I’ll try those things!


#6

So I tried switching boards, to an adafruit bluefruit feather

I also wired up the control pin.

Now I’m getting values in the 100s range.

#include <QTRSensors.h>

// This example is designed for use with six QTR-1A sensors or the first six sensors of a
// QTR-8A module.  These reflectance sensors should be connected to analog inputs 0 to 5.
// The QTR-8A's emitter control pin (LEDON) can optionally be connected to digital pin 2,
// or you can leave it disconnected and change the EMITTER_PIN #define below from 2 to
// QTR_NO_EMITTER_PIN.

// The main loop of the example reads the raw sensor values (uncalibrated).
// You can test this by taping a piece of 3/4" black electrical tape to a piece of white
// paper and sliding the sensor across it.  It prints the sensor values to the serial
// monitor as numbers from 0 (maximum reflectance) to 1023 (minimum reflectance).


#define NUM_SENSORS             1  // number of sensors used
#define NUM_SAMPLES_PER_SENSOR  4  // average 4 analog samples per sensor reading
#define EMITTER_PIN             3  // emitter is controlled by digital pin 2

// sensors 0 through 5 are connected to analog inputs 0 through 5, respectively
QTRDimmableAnalog qtra((unsigned char[]) {2},
  NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, 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()
{
  qtra.setDimmingLevel(0);
  // read raw sensor values
  qtra.read(sensorValues);

  // print the sensor values as numbers from 0 to 1023, where 0 means maximum reflectance and
  // 1023 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.print (analogRead(2));

  }
  Serial.println();

  delay(250);
}

#7

It sounds like the QTRXL-HD-01A sensor is working with your Adafruit Bluefruit Feather. If not, please elaborate on the issue you are having by providing more details (e.g. error messages, behavior descriptions, and printout of sensor values).

- Amanda


#8

It doesn’t seem to be working correctly yet.
The IR led is indeed emitting, but I don’t get a large range of values returned. even when putting it against white and black paper.

‘’’


51	13

109	34

109	33

111	33

108	36

108	36

108	35

122	42

113	35

113	34

112	35

112	36

110	33

109	34

119	35

115	29

116	32

110	31

112	32

111	34

112	33

111	32

110	33

110	34

112	33

110	33

110	33

‘’’

‘’’

#include <QTRSensors.h>

// This example is designed for use with six QTR-1A sensors or the first six sensors of a

// QTR-8A module.  These reflectance sensors should be connected to analog inputs 0 to 5.

// The QTR-8A's emitter control pin (LEDON) can optionally be connected to digital pin 2,

// or you can leave it disconnected and change the EMITTER_PIN #define below from 2 to

// QTR_NO_EMITTER_PIN.

// The main loop of the example reads the raw sensor values (uncalibrated).

// You can test this by taping a piece of 3/4" black electrical tape to a piece of white

// paper and sliding the sensor across it.  It prints the sensor values to the serial

// monitor as numbers from 0 (maximum reflectance) to 1023 (minimum reflectance).

#define NUM_SENSORS             1  // number of sensors used

#define NUM_SAMPLES_PER_SENSOR  4  // average 4 analog samples per sensor reading

#define EMITTER_PIN             3  // emitter is controlled by digital pin 2

// sensors 0 through 5 are connected to analog inputs 0 through 5, respectively

QTRDimmableAnalog qtra((unsigned char[]) {2},

NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, 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()

{

qtra.setDimmingLevel(0);

// read raw sensor values

qtra.read(sensorValues);

// print the sensor values as numbers from 0 to 1023, where 0 means maximum reflectance and

// 1023 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.print (analogRead(2));

}

Serial.println();

delay(250);

}

‘’’


#9

Can you replace 2 with A2 when initializing the qtra object and see if that fixes the problem? If not, can you post a video showing how you are testing the sensor and the distance you are holding the sensor from the paper? Also, can you post the values you get when putting the over the white and black paper?

- Amanda


#10

BINGO That worked.

Thanks for helping a newbie!