Issue with QTR-8RC Sensor on ESP32

I am experiencing an issue with my QTR-8RC sensor array when using it with an ESP32-VROOM-32U. Despite following the setup and calibration procedures, the sensor does not seem to be functioning correctly. Below are the details of my setup and observations:

Setup Details:

Microcontroller: ESP32-VROOM-32U

Power Source: MacBook Air M2

Sensor Array: QTR-8RC (8 sensors)

Connection Pins: 2, 12, 13, 14, 15, 26, 27, 32

Emitter Control Pin: 2

Issue:

The sensor values do not seem to be consistent or correct. As shown in the attached output image, the sensor values remain at 0 or do not vary as expected. Consequently, the position readings and suggested directions (turn left, turn right) are not accurate. Here is a sample of the output I am seeing:

2500 2500 2500 2500 2500 2500 2500 158 
2500 2500 2500 2500 2500 2500 2500 2500 

0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left
0       0       0       0       0       0       0       1000    Position: 7000 - Turn left

Code:

Here is the Arduino code I am using for the setup and calibration of the QTR-8RC sensor array:

#include <Arduino.h>
#include <QTRSensors.h>

QTRSensors qtr;

const uint8_t SensorCount = 8;
uint16_t sensorValues[SensorCount];

void calibrateSensors(){} // implementation of the calibrateSensors function

void setup()
{
  // configure the sensors
  qtr.setTypeRC();
  qtr.setSensorPins((const uint8_t[]){2, 12, 13, 14, 15, 26, 27, 32}, SensorCount);
  qtr.setEmitterPin(2); // emitter is controlled by digital pin 2

  delay(2000); // It is 2000 for test it should be 500 ms for the actual robot
  // 2.5 ms RC read timeout (default) * 10 reads per calibrate() call
  // = ~25 ms per calibrate() call.
  // Call calibrate() 400 times to make calibration take about 10 seconds.
  for (uint16_t i = 0; i < 400; i++)
  {
    qtr.calibrate();
  }

  // print sthe calibration minimum values measured when emitters were on
  Serial.begin(9600);
  for (uint8_t i = 0; i < SensorCount; i++)
  {
    Serial.print(qtr.calibrationOn.minimum[i]);
    Serial.print(' ');
  }
  Serial.println();

  // print the calibration maximum values measured when emitters were on
  for (uint88_t i = 0; i < SensorCount; i++)
  {
    Serial.print(qtr.calibrationOn.maximum[i]);
    Serial.print(' ');
  }
  Serial.println();
  Serial.println();
  delay(10000); // It is 10000 for test it should be 1000 ms for the actual robot
}

void loop()
{
  // read calibrated sensor values and obtain a measure of the line position
  // from 0 to 5000 (for a white line, use readLineWhite() instead)
  uint16_t position = qtr.readLineBlack(sensorValues);

  // print the sensor values as numbers from 0 to 1000, where 0 means maximum
  // reflectance and 1000 means minimum reflectance, followed by the line
  // position (0 to 5000)
  for (uint8_t i = 0; i < SensorCount; i++)
  {
    Serial.print(sensorValues[i]);
    Serial.print('\t');
  }
  Serial.print("Position: ");
  Serial.print(position);
  Serial.print(" - ");

  // Determine direction based on the position of the line
  if (position < 1667) {
    // If position is in the left third, turn left
    Serial.println("Turn right");
  } else if (position > 3333) {
    // If position is in the right third, turn right
    Serial.println("Turn left");
  } else {
    // If position is in the middle third, go straight
    Serial.println("Go straight");
  }

  delay(1000); // It is 1000 for test it should be 250 ms for the actual robot
}

Hello.

It sounds like you are using our older model QTR-8RC Reflectance Sensor Array; is that correct?

You list pin 2 as both a sensor array connection pin and an emitter control pin, which might be causing problems, so can you start by correcting that?

If you continue having issues, please try the QTRRCRawValuesExample.ino example program from the Arduino library for the Pololu QTR Reflectance Sensors with minimal modification (e.g. the pin numbers) and post a sample output from that as you steadily move the array back and forth across the line. Some pictures of your setup that show all of your connections and how you are testing the sensor would also be helpful.

- Patrick

Hello,

Thank you for your response.

I tried the following code and modified the emitter pin. However, all the outputs remain at 2500.

#include <Arduino.h>

#include <QTRSensors.h>

// This example is designed for use with eight RC QTR sensors. These
// reflectance sensors should be connected to digital pins 3 to 10. The
// sensors' emitter control pin (CTRL or LEDON) can optionally be connected to
// digital pin 2, or you can leave it disconnected and remove the call to
// setEmitterPin().
//
// 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 2500 (minimum
// reflectance; this is the default RC timeout, which can be changed with
// setTimeout()).

QTRSensors qtr;

const uint8_t SensorCount = 8;
uint16_t sensorValues[SensorCount];

void setup()
{
  // configure the sensors
  qtr.setTypeRC();
  qtr.setSensorPins((const uint8_t[]){2, 12, 13, 14, 15, 26, 27, 32}, SensorCount);
  qtr.setEmitterPin(25);

  Serial.begin(9600);
}


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

  // print the sensor values as numbers from 0 to 2500, where 0 means maximum
  // reflectance and 2500 means minimum reflectance
  for (uint8_t i = 0; i < SensorCount; i++)
  {
    Serial.print(sensorValues[i]);
    Serial.print('\t');
  }
  Serial.println();

  delay(250);
}

Output:

Here are some images of my setup:


I have checked and ensured that all the sensors are connected to the correct pins as specified in the code. The emitter pin is connected to pin 25. Despite the connections, all sensor readings remain at 2500, indicating minimum reflectance (timeout).

I would appreciate any guidance or suggestions to resolve this issue.

Thank you.

update… I tried again everything is same now 3 sensors are giving some results…

It seems like you are holding your board with a metal alligator clip, which I would not recommend. The uninsulated clip presents a shorting hazard if you clip the board in a bad location. As is, it seems like it might be making a connection to the board’s ground pin.

Can you post pictures showing the solder connections on the top side of your board?

What happens if instead of trying to sense the line, you hold the sensor array facing upwards and cover the sensors one at a time with a piece of paper or your finger?

- Patrick