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

Pololu Forum

QTR8C without Library

Hello, I bought a QTR8C about one week ago and it appears to be working only with the library; I dont want to use the library. Is there something I can do to fix this?
I tried using the following code to read digital values from it, however, I only get zeros after making sure it is powered correctly. Also, I am not sure if it is important but I disconnected the emitter pin.

int rc1, rc2, rc3, rc4, rc5, rc6, rc7, rc8;  // readings from 8 sensors on the side qtr array


void setup() {
  for (int x = 3; x<=10;x++){
    pinMode(x,INPUT);
  }
  Serial.begin(250000);
}

void loop() {
  readValues();
}

void readValues(){
  //Readings from the front qtr array
  rc1 = digitalRead(3);
  rc2 = digitalRead(4);
  rc3 = digitalRead(5);
  rc4 = digitalRead(6);
  rc5 = digitalRead(7);
  rc6 = digitalRead(8);
  rc7 = digitalRead(9);
  rc8 = digitalRead(10);

  Serial.print(rc1);
  Serial.print("\t");
  Serial.print(rc2);
  Serial.print("\t");
  Serial.print(rc3);
  Serial.print("\t");
  Serial.print(rc4);
  Serial.print("\t");
  Serial.print(rc5);
  Serial.print("\t");
  Serial.print(rc6);
  Serial.print("\t");
  Serial.print(rc7);
  Serial.print("\t");
  Serial.print(rc8);
  Serial.println(" ");
  delay(200);
}

Hello.

There is a specific way to read the QTR-RC sensors; you cannot simply use the Arduino digitalRead() function to read the sensor. Each phototransistor is part of a capacitor discharge circuit that allows a digital I/O line to take an analog reading of the reflected IR by measuring the discharge time of the capacitor. You can find more information on how the sensor works in the “RC-type sensor output (intended for digital I/Os)” section of the QTR Reflectance Sensor Application Note. You might find looking at this section of the code for reading QTR-RC in the Arduino library for the Pololu QTR Reflectance Sensors helpful.

- Amanda

Thanks Amanda! The information you shared was very helpful.