Noob needs help setting up QTR RC sensor

Hello. Im having problems getting sensible reading from a single qtr rc sensor. I’m printing out values produced by read() method and all im getting is a bunch 1’s and 2’s. I’m new to this, so im not sure where I went wrong, even though it’s a real simple task im trying to accomplish.
I connected in and out signals to the same arduino digital pin, that’s ok, right? Thank you.

#include <PololuQTRSensors.h>
PololuQTRSensorsRC qtr((unsigned char[]) {2}, 1, 2000, 255);
unsigned int sensors[1];

void setup() {

Serial.begin(19200);	// opens serial port, sets data rate to 9600 bps

  Serial.println("okay, Net Problem");

void loop()


When you say that you are connecting both the in and out signals to the same Arduino pin, do you mean that you have both VIN and OUT connected to Arduino pin 2? If so, this will definitely not work as the sensor needs to be powered while you are reading the output voltage. You should either connect VIN directly to the Arduino’s 5V bus (which will have the IR emitter on all the time), or you can connect it to a second digital output that you drive high before attempting to read the sensor.

If I misunderstood your post, please let me know. Otherwise, please tell me if changing your connections as described above solves the problem.

- Ben

Heh thanks a lot Ben!

Hi, did you make this work? i have an array of 5 QTR RC sensors and i’m not receiving the desired data from them, i’m using this program:

-Platform: Ubuntu GNU/Linux
-Arduino: Duemilanove
-GCC version 4.3.3
-Pololu libs version:

#include <PololuQTRSensors.h>   

void sensor_activo(int s, unsigned int valor);

PololuQTRSensorsRC qtrrc((unsigned char[]) {2, 3, 4, 5, 6}, 5, 2000);

void setup()                    // run once, when the sketch starts
    Serial.println("Iniciando debug en tty");    
    // calibrando el sensor
    // then start calibration phase and move the sensors over both
    // reflectance extremes they will encounter in your application:
    int i;
    for (i = 0; i < 250; i++) // make the calibration take about 5 seconds

void loop()                     // run over and over again
    unsigned int vsensores[5];;
    digitalWrite(ledPin, HIGH);  // turn the ledPin on
    // imprimir los valores que tiene el sensor
    Serial.println("valores de los sensores");
    for (int i=0; i<5; i++){

void sensor_activo(int s, unsigned int valor){
    Serial.print("Se ha activado el sensor ");

But i only get the value 2000 returned from the sensors, is anything special to take on acount building the breadboard? any resistance or something?

thanks a lot for your help


Are you using five individual QTR-1RC sensors, or are you using five sensors from a QTR-8RC sensor array? If you are using the array, are your emitters on? What happens if you just use seriouja’s code, which only looks at a single sensor and doesn’t perform an initial calibration?

- Ben

I’m having a similar problem – QTR 8C returning “4000” (timeout?).

I’m using a Seeeduino v1.1 (ATmega168). I’ve posted some code and pictures on my build log. I’ve tried some posted code that others have claimed will work, and still have problems. I think this points to a problem with hardware or configuration. … ot-working

I see some people posting about pin assignment differences between versions of Arduino. Could this be a problem?

Tim Klein


I’m not sure what it is about the Arduino/Arduino environment that keeps our sample line sensor code from working properly, but it is fairly easy to write some simple code yourself that reads the sensors (perhaps you’re using another library that conflicts with the QTR library?). If you can write a routine that reads the sensor values, you can then copy the higher-level portions of the library that convert these readings into a line position.

Please see the following thread for more information and some sample code. If you want to discuss more complicated routines for reading the sensors, please continue the discussion in this thread:

- Ben


Just to follow up with this, I have updated the Arduino library for the QTR sensors. It should now work for both analog (A) and digital (RC) versions on all Arduinos, and it relies on standard Arduino functions, so it shouldn’t conflict with any other libraries. The library also now includes two sample sketches (one for each sensor version). Please let me know if you have any problems with it.

- Ben

Thanks Ben. I’ve verified that this works on my Seeeduino (“v1.1 8/23/2008”). I edited the header to the following parameters. All other code was unaltered.

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

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

Looks like I’m back on track for my line follower project. Thanks again.